![](/img/trans.png)
[英]Convert Delimiter fille to JSON format using Dataweave in Mule
[英]Output in Json format using dataweave
我正在嘗試將字段值映射從CSV轉換為Json格式,下面的代碼是我的dataweave代碼,用於將字段從CSV映射並將其轉換為Json格式:
%dw 1.0
%output application/json
---
{
"volume":
[
payload groupBy $.StartDate map ((val,cal) ->
{
StartDate:val.StartDate[0],
rows :
[
{
AccountID : val.AccountID,
ProductID : val.ProductID,
Value : val.Value
}
]
}
)
]
}
我獲得如下輸出:-
{
"volume": [
[
{
"StartDate": "8/1/2016",
"AccountID": [
"16482965",
"16482966"
],
"ProductID": [
"12235398476-AR02",
"12235398477-AR03"
],
"Value": [
"1720",
"1722"
]
},
.
.
.
但我希望我的輸出如下所示:
{
"volume": [
[
{
"StartDate": "8/1/2016",
"AccountID":"16482965","ProductID":"12235398476-AR02","Value":"1720",
"AccountID":"16482966","ProductID":"12235398477-AR03","Value": "1722"
},
.
.
.
有人可以在這里嗎?
根據您對我的問題的回答,這是您需要構造的JSON結構:
{
"volume": [
{
"StartDate": "8/1/2016",
"Entries": [
{"AccountID":"16482965","ProductID":"12235398476-AR02","Value":"1720"},
{"AccountID":"16482966","ProductID":"12235398477-AR03","Value":"1722"}
]
},
...
]
.
.
.
}
注意在結構中添加了"Entries"
元素。 它將允許您使用以下引用來遍歷數組:
...volume[n].Entries[j].AccountID
希望這會使您更清楚。
更新 :我錯過了閉幕]
。 現在添加。
我使用了以下代碼,請您確認
%dw 1.0
%output application/json
---
{
"Transaction":"111",
"type":"b002",
"volume":
[
payload groupBy $.StartDate map ((val,cal) ->
{
StartDate:val.StartDate[0],
"Entries" :
[
{
AccountID : val.AccountID,
ProductID : val.ProductID,
Value : val.Value
}
]
}
)
]
}
And iam still getting the out put as :
{
"Transaction": "111",
"type": "b002",
"volume": [
[
{
"StartDate": "8/1/2016",
"Entries": [
{
"AccountID": [
"16482965",
"16482966"
],
"ProductID": [
"12235398476-AR02",
"12235398477-AR03"
],
"Value": [
"1720",
"1722"
]
}
]
},
{
"StartDate": "7/31/2016",
"Entries": [
{
"AccountID": [
"16482964"
],
"ProductID": [
"12235398475-AR01"
],
"Value": [
"1720"
]
}
]
}
]
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.