Mulesoft 将多个 JSON/XML 转换为 CSV
Mulesoft transform multiple JSON/XML to CSV
我对在 Mulesoft 中将 JSON 转换为 CSV 完全陌生。目前我需要努力将嵌套的 JSON 转换为 CSV,我的 CSV 应该像这样 而我的 JSON 会像
{
"Invoice": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Status": "",
"Invoice Date*": ""
}
],
"Invoice Line": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Line Number": "",
"Description*": "",
"Supplier Part Number": "",
"Auxiliary Part Number": "",
"Price*": "",
"Quantity": "",
"Bulk Price": "",
"Bulk Price Qty": ""
}
],
"Invoice Tax Line": [
{
"Invoice Number*": "",
"Invoice Line Number": "",
"Invoice Charge Number": "",
"Line Number": "",
"Tax Amount": "",
"Tax Rate": "",
"Tax Code": "",
"Tax Rate Type": ""
}
]
}
我对 CSV 的了解是只有一个 header。将这个复杂的 JSON 映射到显示不同 header 的 CSV 中的最佳方法是什么?
你可以这样做:
%dw 2.0
output application/csv header=false
---
flatten (
[
{"Invoice Number":"Invoice Number",
"Supplier Name": "Supplier Name",
"Supplier Number" :"Supplier Number",
"Status" : "Status",
"Invoice Date*" : "Invoice Date*"
},
{
"Invoice Number":"Invoice Number*",
"Supplier Name":"Supplier Name",
"Supplier Number":"Supplier Number",
"Status":"Status",
"Invoice Date*":"Invoice Date*"
},
payload.Invoice map {
"Invoice Number":$."Invoice Number*",
"Supplier Name":$."Supplier Name",
"Supplier Number":$."Supplier Number",
"Status":$.Status,
"Invoice Date*":$."Invoice Date*"
},
payload."Invoice Line" map {
"Invoice Number": $."Invoice Number*",
"Supplier Name":$."Supplier Name",
...
}
,
payload."Invoice Tax Line" map {
"Invoice Number":$."Invoice Number*",
...
}
]
)
我对在 Mulesoft 中将 JSON 转换为 CSV 完全陌生。目前我需要努力将嵌套的 JSON 转换为 CSV,我的 CSV 应该像这样
{
"Invoice": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Status": "",
"Invoice Date*": ""
}
],
"Invoice Line": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Line Number": "",
"Description*": "",
"Supplier Part Number": "",
"Auxiliary Part Number": "",
"Price*": "",
"Quantity": "",
"Bulk Price": "",
"Bulk Price Qty": ""
}
],
"Invoice Tax Line": [
{
"Invoice Number*": "",
"Invoice Line Number": "",
"Invoice Charge Number": "",
"Line Number": "",
"Tax Amount": "",
"Tax Rate": "",
"Tax Code": "",
"Tax Rate Type": ""
}
]
}
我对 CSV 的了解是只有一个 header。将这个复杂的 JSON 映射到显示不同 header 的 CSV 中的最佳方法是什么?
你可以这样做:
%dw 2.0
output application/csv header=false
---
flatten (
[
{"Invoice Number":"Invoice Number",
"Supplier Name": "Supplier Name",
"Supplier Number" :"Supplier Number",
"Status" : "Status",
"Invoice Date*" : "Invoice Date*"
},
{
"Invoice Number":"Invoice Number*",
"Supplier Name":"Supplier Name",
"Supplier Number":"Supplier Number",
"Status":"Status",
"Invoice Date*":"Invoice Date*"
},
payload.Invoice map {
"Invoice Number":$."Invoice Number*",
"Supplier Name":$."Supplier Name",
"Supplier Number":$."Supplier Number",
"Status":$.Status,
"Invoice Date*":$."Invoice Date*"
},
payload."Invoice Line" map {
"Invoice Number": $."Invoice Number*",
"Supplier Name":$."Supplier Name",
...
}
,
payload."Invoice Tax Line" map {
"Invoice Number":$."Invoice Number*",
...
}
]
)