I am pretty new to JOLTtransform and I’m trying to understand it better. I tried alot of stuff but i didnt work out. I try to take a List of JSONS and Split them so i can put it in a Database while with the KH and ref on each TRD field.
Input:
[
{
"KH": "12",
"ref": "1808",
"TRD": [
{
"KATEGORIE": "KH10",
"NR": 1,
"DNR": "02209394"
},
{
"KATEGORIE": "KH10",
"NR": 2,
"DNR": "00761006"
},
{
"KATEGORIE": "KH20",
"NR": 3,
"DNR": "09999092"
}
]
},
{
"KH": "12",
"ref": "1808",
"TRD": [
{
"KATEGORIE": "KH10",
"NR": 1,
"DNR": "01018143"
},
{
"KATEGORIE": "KH20",
"NR": 2,
"DNR": "085859973"
}
]
}
]
And expected Output:
[
{
"KH": "12",
"ref": "1808",
"NR": 1,
"KATEGORIE": "KH10",
"DNR": "02209394"
},
{
"KH": "12",
"ref": "1808",
"NR": 2,
"KATEGORIE": "KH10",
"DNR": "00761006"
},
{
"KH": "12",
"ref": "1808",
"NR": 3,
"KATEGORIE": "KH20",
"DNR": "09999092"
},
{
"KH": "12",
"ref": "1808",
"NR": 1,
"KATEGORIE": "KH10",
"DNR": "01018143"
},
{
"KH": "12",
"ref": "1808",
"NR": 2,
"KATEGORIE": "KH20",
"DNR": "085859973"
}
]
Im using :
[
{
"operation": "shift",
"spec": {
"*": {
"TRD": {
"*": {
"@(2,KH)": "[#2].KH",
"@(2,ref)": "[#2].ref",
"KATEGORIE": "[#2].KATEGORIE",
"NR": "[#2].NR",
"DNR": "[#2].DNR"
}
}
}
}
}
]
and im getting:
[
{
"DNR" : [ "02209394", "01018143" ],
"KATEGORIE" : [ "KH10", "KH10" ],
"KH" : [ "12", "12" ],
"NR" : [ 1, 1 ],
"ref" : [ "1808", "1808" ]
},
{
"DNR" : [ "00761006", "085859973" ],
"KATEGORIE" : [ "KH10", "KH20" ],
"KH" : [ "12", "12" ],
"NR" : [ 2, 2 ],
"ref" : [ "1808", "1808" ]
},
{
"DNR" : "09999092",
"KATEGORIE" : "KH20",
"KH" : "12",
"NR" : 3,
"ref" : "1808"
}
]
i dont know where i go wrong. I tried chatGPT but it made it even worse lol
2
Answers
You can use the below spec
You can apply two different tiers of grouping of indexes as in the following case :
the demo on the site http://jolt-demo.appspot.com/ is :
or you can handle it more dynamically(eg. without writing each attribute
"KH"
and"ref"
individually) by using the following tranformationthe demo on the site http://jolt-demo.appspot.com/ is :