Skip to content

Data Transform

CSV, JSON, XML, YAML parsing, generation, and pipeline transformations.

16 modules

ModuleDescription
Đọc tệp CSVĐọc và phân tích tệp CSV thành mảng các đối tượng
Ghi tệp CSVGhi mảng các đối tượng vào tệp CSV
Phân tích JSONPhân tích chuỗi JSON thành đối tượng
JSON StringifyChuyển đổi đối tượng thành chuỗi JSON
JSON sang CSVChuyển đổi dữ liệu hoặc tệp JSON sang định dạng CSV
Dòng dữ liệuKết hợp nhiều biến đổi dữ liệu trong một bước
Template văn bảnĐiền các biến vào template văn bản
Tạo XMLTạo chuỗi XML từ đối tượng hoặc mảng
Phân tích XMLPhân tích chuỗi XML thành đối tượng
Tạo YAMLTạo chuỗi YAML từ đối tượng hoặc mảng
Phân tích YAMLPhân tích chuỗi YAML thành đối tượng
Khóa đối tượngLấy tất cả các khóa từ một đối tượng
Gộp đối tượngGộp nhiều đối tượng thành một
Bỏ qua đối tượngBỏ qua các khóa cụ thể từ một đối tượng
Chọn đối tượngChọn các khóa cụ thể từ một đối tượng
Giá trị đối tượngLấy tất cả các giá trị từ một đối tượng

Modules

Đọc tệp CSV

data.csv.read

Đọc và phân tích tệp CSV thành mảng các đối tượng

Parameters:

NameTypeRequiredDefaultDescription
pathstringYes-Path to the file
delimiterselect (,, ;, , `, `)No,
encodingselect (utf-8, ascii, latin-1, utf-16, gbk, big5)Noutf-8Character encoding for the file
skip_headerbooleanNoFalseSkip first row (header)

Output:

FieldTypeDescription
statusstringTrạng thái thao tác
dataarrayTrạng thái thao tác
rowsnumberTrạng thái thao tác
columnsarrayMảng các đối tượng hàng

Example: Example

yaml
file_path: data/users.csv
delimiter: ,
encoding: utf-8

Ghi tệp CSV

data.csv.write

Ghi mảng các đối tượng vào tệp CSV

Parameters:

NameTypeRequiredDefaultDescription
pathstringYes-Path to the file
dataarrayYes-Array of data items to process
delimiterselect (,, ;, , `, `)No,
encodingselect (utf-8, ascii, latin-1, utf-16, gbk, big5)Noutf-8Character encoding for the file

Output:

FieldTypeDescription
statusstringTrạng thái thao tác
file_pathstringTrạng thái thao tác
rows_writtennumberTrạng thái thao tác

Example: Example

yaml
file_path: output/results.csv
data: [{"name": "John", "score": 95}, {"name": "Jane", "score": 87}]

Phân tích JSON

data.json.parse

Phân tích chuỗi JSON thành đối tượng

Parameters:

NameTypeRequiredDefaultDescription
json_stringstringYes-JSON string to parse into an object or array

Output:

FieldTypeDescription
statusstringTrạng thái thao tác
dataobjectTrạng thái thao tác

Example: Example

yaml
json_string: {"name": "John", "age": 30}

JSON Stringify

data.json.stringify

Chuyển đổi đối tượng thành chuỗi JSON

Parameters:

NameTypeRequiredDefaultDescription
dataobjectYes-Data object to process
prettybooleanNoFalseFormat with indentation
indentnumberNo2Indentation spaces (if pretty=true)

Output:

FieldTypeDescription
statusstringTrạng thái thao tác
jsonstringTrạng thái thao tác

Example: Example

yaml
data: {"name": "John", "age": 30}
pretty: true

JSON sang CSV

data.json_to_csv

Chuyển đổi dữ liệu hoặc tệp JSON sang định dạng CSV

Parameters:

NameTypeRequiredDefaultDescription
input_dataanyYes-JSON data (array of objects) or path to JSON file
output_pathstringNo/tmp/output.csvPath where the output file will be saved
delimiterselect (,, ;, , `, `)No,
include_headerbooleanNoTrueInclude column headers in first row
flatten_nestedbooleanNoTrueFlatten nested objects using dot notation (e.g., address.city)
columnsarrayNo[]Specific columns to include (empty = all columns)

Output:

FieldTypeDescription
output_pathstringĐường dẫn đến tệp CSV đã tạo
row_countnumberĐường dẫn đến tệp CSV đã tạo
column_countnumberĐường dẫn đến tệp CSV đã tạo
columnsarraySố hàng đã ghi

Example: Convert JSON array to CSV

yaml
input_data: [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
output_path: /tmp/users.csv

Example: Convert JSON file

yaml
input_data: /path/to/data.json
output_path: /path/to/output.csv

Dòng dữ liệu

data.pipeline

Kết hợp nhiều biến đổi dữ liệu trong một bước

Parameters:

NameTypeRequiredDefaultDescription
inputanyYes-Dữ liệu đầu vào để biến đổi (mảng hoặc đối tượng)
stepsarrayYes-Dữ liệu đầu vào để biến đổi (mảng hoặc đối tượng)

Output:

FieldTypeDescription
resultanyMảng các bước biến đổi cần áp dụng theo thứ tự
original_countintegerDữ liệu đã biến đổi
result_countintegerDữ liệu đã biến đổi
steps_appliedintegerSố lượng mục sau khi biến đổi

Example: Example

yaml
input: ${input.users}
steps: [{"filter": {"field": "active", "condition": "eq", "value": true}}, {"sort": {"field": "name", "order": "asc"}}]

Example: Example

yaml
input: ${input.records}
steps: [{"map": {"extract": "id"}}, {"limit": 10}]

Example: Example

yaml
input: ${input.data}
steps: [{"filter": {"field": "status", "condition": "eq", "value": "completed"}}, {"pick": ["id", "name", "timestamp"]}, {"sort": {"field": "timestamp", "order": "desc"}}, {"skip": 5}, {"limit": 20}]

Template văn bản

data.text.template

Điền các biến vào template văn bản

Parameters:

NameTypeRequiredDefaultDescription
templatestringYes-Text template with {variable} placeholders
variablesobjectYes-Object with variable values

Output:

FieldTypeDescription
statusstringTrạng thái thao tác
resultstringTrạng thái thao tác

Example: Example

yaml
template: Hello {name}, you scored {score} points!
variables: {"name": "Alice", "score": 95}

Tạo XML

data.xml.generate

Tạo chuỗi XML từ đối tượng hoặc mảng

Parameters:

NameTypeRequiredDefaultDescription
dataobjectYes-Dữ liệu để chuyển đổi thành XML
root_tagstringNorootTên thẻ phần tử gốc
prettybooleanNoTrueIn đẹp đầu ra XML
encodingstringNoutf-8Mã hóa ký tự cho đầu ra XML
declarationbooleanNoTrueBao gồm tiêu đề khai báo XML

Output:

FieldTypeDescription
xmlstringChuỗi XML đã tạo

Example: Example

yaml
data: {"user": {"@attributes": {"id": "1"}, "name": "John", "age": "30"}}
root_tag: users
pretty: true

Phân tích XML

data.xml.parse

Phân tích chuỗi XML thành đối tượng

Parameters:

NameTypeRequiredDefaultDescription
contentstringNo-Chuỗi XML để phân tích
file_pathstringNo-Đường dẫn đến tệp XML để phân tích
preserve_attributesbooleanNoTrueGiữ lại thuộc tính XML trong đầu ra đã phân tích

Output:

FieldTypeDescription
resultobjectXML đã phân tích dưới dạng đối tượng
root_tagstringTên thẻ phần tử gốc

Example: Example

yaml
content: <users><user id="1"><name>John</name></user></users>
preserve_attributes: true

Tạo YAML

data.yaml.generate

Tạo chuỗi YAML từ đối tượng hoặc mảng

Parameters:

NameTypeRequiredDefaultDescription
dataanyYes-Dữ liệu để chuyển đổi thành YAML
default_flow_stylebooleanNoFalseSử dụng kiểu dòng cho cấu trúc lồng nhau
sort_keysbooleanNoFalseSắp xếp khóa theo thứ tự chữ cái
indentnumberNo2Số khoảng trắng để thụt lề
allow_unicodebooleanNoTrueCho phép ký tự unicode trong đầu ra

Output:

FieldTypeDescription
yamlstringChuỗi YAML đã tạo

Example: Example

yaml
data: {"name": "John", "age": 30, "cities": ["NYC", "LA"]}
sort_keys: false
indent: 2

Phân tích YAML

data.yaml.parse

Phân tích chuỗi YAML thành đối tượng

Parameters:

NameTypeRequiredDefaultDescription
contentstringNo-Chuỗi YAML để phân tích
file_pathstringNo-Đường dẫn đến tệp YAML để phân tích
multi_documentbooleanNoFalsePhân tích YAML nhiều tài liệu (ngăn cách bằng ---)

Output:

FieldTypeDescription
resultanyYAML đã phân tích dưới dạng đối tượng hoặc mảng
typestringLoại của kết quả đã phân tích

Example: Example

yaml
content: name: John
age: 30
cities:
  - NYC
  - LA
multi_document: false

Example: Example

yaml
content: ---
name: John
---
name: Jane
multi_document: true

Khóa đối tượng

object.keys

Lấy tất cả các khóa từ một đối tượng

Parameters:

NameTypeRequiredDefaultDescription
objectobjectYes-Input object/dictionary

Output:

FieldTypeDescription
keysarrayDanh sách các khóa đối tượng
countnumberDanh sách các khóa đối tượng

Example: Get object keys

yaml
object: {"name": "John", "age": 30, "city": "NYC"}

Gộp đối tượng

object.merge

Gộp nhiều đối tượng thành một

Parameters:

NameTypeRequiredDefaultDescription
objectsarrayYes-Array of objects to process

Output:

FieldTypeDescription
resultobjectĐối tượng đã gộp

Example: Merge user data

yaml
objects: [{"name": "John", "age": 30}, {"city": "NYC", "country": "USA"}, {"job": "Engineer"}]

Bỏ qua đối tượng

object.omit

Bỏ qua các khóa cụ thể từ một đối tượng

Parameters:

NameTypeRequiredDefaultDescription
objectobjectYes-Input object/dictionary
keysarrayYes-Keys to pick or omit

Output:

FieldTypeDescription
resultobjectĐối tượng không có các khóa đã bỏ qua

Example: Omit sensitive fields

yaml
object: {"name": "John", "age": 30, "password": "secret", "ssn": "123-45-6789"}
keys: ["password", "ssn"]

Chọn đối tượng

object.pick

Chọn các khóa cụ thể từ một đối tượng

Parameters:

NameTypeRequiredDefaultDescription
objectobjectYes-Input object/dictionary
keysarrayYes-Keys to pick or omit

Output:

FieldTypeDescription
resultobjectĐối tượng chỉ có các khóa đã chọn

Example: Pick user fields

yaml
object: {"name": "John", "age": 30, "email": "john@example.com", "password": "secret"}
keys: ["name", "email"]

Giá trị đối tượng

object.values

Lấy tất cả các giá trị từ một đối tượng

Parameters:

NameTypeRequiredDefaultDescription
objectobjectYes-Input object/dictionary

Output:

FieldTypeDescription
valuesarrayDanh sách các giá trị đối tượng
countnumberDanh sách các giá trị đối tượng

Example: Get object values

yaml
object: {"name": "John", "age": 30, "city": "NYC"}

Released under the Apache 2.0 License.