[英]Output in Json format using dataweave
I'm trying to convert the field-value mapping from CSV to Json format,below code is my dataweave code for mapping the fields from CSV and converting it into Json format: 我正在尝试将字段值映射从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
}
]
}
)
]
}
Iam getting output as below :- 我获得如下输出:-
{
"volume": [
[
{
"StartDate": "8/1/2016",
"AccountID": [
"16482965",
"16482966"
],
"ProductID": [
"12235398476-AR02",
"12235398477-AR03"
],
"Value": [
"1720",
"1722"
]
},
.
.
.
But i want my output to look like below : 但我希望我的输出如下所示:
{
"volume": [
[
{
"StartDate": "8/1/2016",
"AccountID":"16482965","ProductID":"12235398476-AR02","Value":"1720",
"AccountID":"16482966","ProductID":"12235398477-AR03","Value": "1722"
},
.
.
.
Can anybody please here? 有人可以在这里吗?
According to your answer to my question, here is the JSON structure you need to construct: 根据您对我的问题的回答,这是您需要构造的JSON结构:
{
"volume": [
{
"StartDate": "8/1/2016",
"Entries": [
{"AccountID":"16482965","ProductID":"12235398476-AR02","Value":"1720"},
{"AccountID":"16482966","ProductID":"12235398477-AR03","Value":"1722"}
]
},
...
]
.
.
.
}
Note the addition of the "Entries"
element to the structure. 注意在结构中添加了"Entries"
元素。 It will allow you to run through the array by using references like: 它将允许您使用以下引用来遍历数组:
...volume[n].Entries[j].AccountID
Hope this makes things clearer for you. 希望这会使您更清楚。
UPDATE : I missed a closing ]
. 更新 :我错过了闭幕]
。 Added now. 现在添加。
i have used the below code,can you please confirm 我使用了以下代码,请您确认
%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.