admin管理员组文章数量:1316617
I have the following json (source) and I would like to transform it into the target json. All objects of array "temp" should be integrated in "attributes".
Everytime I try to insert an object to "attributes" I create an array within an array.
Any Help is highly appreciated. I think there is a quick fix, but I haven't found it after hours of research
Source
{
"items": [
{
"itemNo": "abc-4711",
"attributes": [
{
"id": "length_lanyard",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "rope_length",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
}
],
"temp": [
{
"id": "length_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
},
{
"id": "rope_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
}
]
}
]
}
target
{
"items": [
{
"itemNo": "abc123",
"attributes": [
{
"id": "length_lanyard",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "rope_length",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "length_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
},
{
"id": "rope_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
}
]
}
]
}
I have the following json (source) and I would like to transform it into the target json. All objects of array "temp" should be integrated in "attributes".
Everytime I try to insert an object to "attributes" I create an array within an array.
Any Help is highly appreciated. I think there is a quick fix, but I haven't found it after hours of research
Source
{
"items": [
{
"itemNo": "abc-4711",
"attributes": [
{
"id": "length_lanyard",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "rope_length",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
}
],
"temp": [
{
"id": "length_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
},
{
"id": "rope_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
}
]
}
]
}
target
{
"items": [
{
"itemNo": "abc123",
"attributes": [
{
"id": "length_lanyard",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "rope_length",
"type": "float",
"values": [
{
"value": "0.40",
"unit_of_measure": "m"
}
]
},
{
"id": "length_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
},
{
"id": "rope_lanyard_imp",
"type": "float",
"imp_length_lanyard": {
"values": [
{
"value": 1.30,
"unit_of_measure": "feet"
}
]
}
}
]
}
]
}
Share
Improve this question
asked Jan 30 at 14:08
Katja BürgerKatja Bürger
351 silver badge6 bronze badges
1 Answer
Reset to default 1You can use the following shift transformation spec :
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2[&1].&",
"attributes|temp": { //accumulate under common node, namely "attributes"
"*": {
"*": "&4[&3].attributes.@1,id.&"//presumingly ids are unique for the whole JSON
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2[&1].&",
"attributes": { //reindex the stuff under the common node
"*": "&3[&2].&1"
}
}
}
}
}
]
the demo on the site Jolt Transform Demo Using v0.1.1 is :
本文标签: jsonintegrating the objects of one array into a second array with JOLTStack Overflow
版权声明:本文标题:json - integrating the objects of one array into a second array with JOLT - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741960239a2407234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论