[英]mule : how to convert list of maps to list of JSon in dataweave?
I have input data as list of maps like [{id="200" name="aaa"},{id="100",name="shbd"}]
. 我将输入数据作为地图列表,例如
[{id="200" name="aaa"},{id="100",name="shbd"}]
。 I want to transform it to JSON like below 我想将其转换为JSON,如下所示
{
[
{
id="200",
name="aaa"
},
{
id="100",
name="shbd"
}
]
}
If the fields(keys in map) do no change, then it is simple and straightforward. 如果字段(映射中的键)没有变化,则它简单明了。 Now how to transform if I dont know the key values.
现在,如果我不知道键值,该如何转换。 For eg, what if after sometime the input of map is
[{"age":90},{"age","45"}]
例如,如果某个时间之后地图的输入是
[{"age":90},{"age","45"}]
It's always better to do specific mapping but you can go with the following , it will transform it into JSON 进行特定映射总是更好,但是您可以执行以下操作,它将其转换为JSON
%dw 1.0
%output application/json
---
payload
As Anirban said, please validate the json you want to transform. 正如Anirban所说,请验证要转换的json。 You can use below transformation for o/p specified below:
您可以对以下指定的o / p使用以下转换:
Transformation
---------------
%dw 1.0
%output application/json
---
payload map {
"id" : $.id,
"name" : $.name
}
---------------
expected output
--------------
[
{
id="200",
name="aaa"
},
{
id="100",
name="shbd"
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.