Reputation: 62
I am attempting to create a jolt transformation for the below input:
{
"admin": [
{
"heading": "header1",
"fields": [
{
"description": "Name",
"value": "John"
},
{
"description": "Foo",
"value": "Bar"
}
],
"id": "123456"
},
{
"heading": "header2",
"fields": [
{
"description": "Name",
"value": "Jane"
},
{
"description": "Foo",
"value": "Bar"
}
],
"id": "789123"
}
]
}
with the desired output of:
{
"admin":
{
"header1":
{
"Name" : "John",
"Foo": "Bar",
"id": "123456"
},
"header2":
{
"Name" : "Jane",
"Foo": "Bar"
"id": "789123"
},
}
}
I have just started understanding the basics of jolt transformations, but this seems a little complex with the nested structures.
Upvotes: 1
Views: 531
Reputation: 2116
This spec does what you want
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"id": "admin.@(1,heading).id",
"*": {
"*": {
"value": "admin.@(3,heading).@(1,description)"
}
}
}
}
}
}
]
This spec loops through the fields array and matches the description field to the keys looking up a level above with the value.
Upvotes: 1