[英]I need this json data in the below format using JSONATA
Below json is my input. json以下是我的输入。
{
"payload": {
"KA01B3432": "KA01B3432",
"KA02A3123": "KA02A3123"
}
}
Using JSONATA i need to format the above JSON to below format. 使用JSONATA我需要将上面的JSON格式化为以下格式。
[
{
"KA01B3432": "KA01B3432"
},
{
"KA02A3123": "KA02A3123"
}
]
I tried payload.[$keys()]
but this will yield only keys in array format not whole object in array format. 我尝试了payload.[$keys()]
但这只会产生数组格式的键而不是数组格式的整个对象。
{
"payload": {
"KA01B3432": "KA01B3432",
"KA02A3123": "KA02A3123"
}
}
to 至
[
{
"KA01B3432": "KA01B3432"
},
{
"KA02A3123": "KA02A3123"
}
]
What about the following code : 以下代码如何:
var json = { "payload": { "KA01B3432": "KA01B34321", "KA02A3123": "KA02A31231" } };
var array = [];
keys = Object.keys(json.payload);
values = Object.values(json.payload);
for (var i = 0; i < keys.length; i++) {
var item = {};
item[keys[i]] = values[i];
array.push(item);
}
console.log(array);
$spread(payload)
does what you need. $spread(payload)
可以满足您的需求。
See http://try.jsonata.org/S1COdDqO4 见http://try.jsonata.org/S1COdDqO4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.