Created 05-23-2019 09:22 AM
Hi, I need some help with JOLT-syntax.
JSON-Input
{
"nummer": "1073",
"table": [
{
"datum": "20180529",
"zn": 1
},
{
"datum": "20180530",
"zn": 2
},
{
"datum": "20190522",
"zn": 3
}
]
}JOLT-Specification
[{
"operation": "shift",
"spec": {
"nummer": "Nummer",
"table": {
"*": {
"zn": "Positionen.[].ZeileNr",
"datum": "Positionen.[].Datum"
}
}
}
}
]JSON-Output
{
"Nummer": "1073",
"Positionen": [{
"ZeileNr": 1
}, {
"Datum": "20180529"
}, {
"ZeileNr": 2
}, {
"Datum": "20180530"
}, {
"ZeileNr": 3
}, {
"Datum": "20190522"
}]
}But the JSON-Output what I need is:
{
"Nummer": "1073",
"Positionen": [{
"ZeileNr": 1,
"Datum": "20180529"
}, {
"ZeileNr": 2,
"Datum": "20180530"
}, {
"ZeileNr": 3,
"Datum": "20190522"
}]
}Please, how can I manage this, it is driving me crazy...
Thanks for any help and information about this syntax!
Created 05-24-2019 02:37 AM
You were so close! By using the [] syntax it just adds to the outgoing array, but you wanted to associate them with the same index, namely the one matched by the * "above" the fields. Put #2 inside your braces (#2 is a reference to the array index you're iterating over, "two levels up" from where you are in the spec):
[{
"operation": "shift",
"spec": {
"nummer": "Nummer",
"table": {
"*": {
"zn": "Positionen.[#2].ZeileNr",
"datum": "Positionen.[#2].Datum"
}
}
}
}]
Created 05-24-2019 02:37 AM
You were so close! By using the [] syntax it just adds to the outgoing array, but you wanted to associate them with the same index, namely the one matched by the * "above" the fields. Put #2 inside your braces (#2 is a reference to the array index you're iterating over, "two levels up" from where you are in the spec):
[{
"operation": "shift",
"spec": {
"nummer": "Nummer",
"table": {
"*": {
"zn": "Positionen.[#2].ZeileNr",
"datum": "Positionen.[#2].Datum"
}
}
}
}]