I am trying to convert the input JSON
{
"Main header": {
"line1": [
{
"model": "Cooper",
"year": 2018,
"type": "Hatchback",
"motorization": "Electric",
"colour": "Midnight Black",
"stageID": "MGOP94810482042"
}
],
"line2": [
{
"model": "Cooper",
"year": 2018,
"type": "Hatchback",
"motorization": "Diesel",
"colour": "Silver",
"stageID": "MGOP9183740194"
}
]
}
}
to output
{
"My header": {
"This is line 1": [
{
"Car Model": "Cooper",
"Car Year": 2018,
"type": "Hatchback",
"motorization": "Electric",
"colour": "Midnight Black",
"stageID": "MGOP94810482042"
}
],
"This is line 2": [
{
"model": "Cooper",
"year": 2018,
"type": "Hatchback",
"motorization": "Diesel",
"colour": "Silver",
"stageID": "MGOP9183740194"
}
]
}
}
I can perform this in multiple different steps.
- Rename line1 and line 2 headers
[
{
"operation": "shift",
"spec": {
"Main header": {
"*": {
"@": "&"
},
"line1": {
"@": "Line 1 header"
},
"line2": {
"@": "Line 2 header"
}
}
}
}
]
- Rename specific keys in a array
[
{
"operation": "shift",
"spec": {
"Main header": {
"line1": {
"*": {
"model": "Main header.line1.[&1].Car Model",
"year": "Main header.line1.[&1].Car Year"
}
}
}
}
}
]
I am trying to create a combined jolt transform spec that can perform this conversion. I tried creating a couple of merged versions and one or the other doesn't seem to work. Any help or guidance is much appreciated!
EDIT
I managed to club the two operations and arrived at the below spec
//Rename nested keys in array
[
{
"operation": "shift",
"spec": {
"Main header": {
"line1": {
"*": {
"model": "My Header.This is line 1.[&1].Car Model",
"year": "My Header.This is line 1.[&1].Car Year",
"@": "My Header.This is line 1.[&]"
}
},
"line2": {
"*": {
"model": "My Header.This is line 2.[&1].Car Model",
"year": "My Header.This is line 2.[&1].Car Year",
"@": "My Header.This is line 2.[&]"
}
}
}
}
}
]
But when I run this spec, there are two new keys (the ones I renamed) and all the existing keys are also present in the output. Is there a way I can remove the keys that I have renamed?
My latest output
{
"My Header" : {
"This is line 1" : [ {
"model" : "Cooper",
"year" : 2018,
"type" : "Hatchback",
"motorization" : "Electric",
"colour" : "Midnight Black",
"stageID" : "MGOP94810482042",
"Car Model" : "Cooper",
"Car Year" : 2018
} ],
"This is line 2" : [ {
"model" : "Cooper",
"year" : 2018,
"type" : "Hatchback",
"motorization" : "Diesel",
"colour" : "Silver",
"stageID" : "MGOP9183740194",
"Car Model" : "Cooper",
"Car Year" : 2018
} ]
}
}