Here is the input JSON that I will put into the JOLT transformation processor in NiFi.
"guests" : {
"amy" : "amy",
"theresa" : [ "Chef" ],
"jim" : [ "Bear Specialist" ],
"john" : [ "Tour Guide" ],
"heather" : [ "" ],
"brad" : [ "" ],
"thomas" : [ "" ],
"jane" : [ "" ]
},
"dataSchema" : "dataSchema",
"data" : {
"key1" : "value1",
"key2" : {
"key3" : "value3",
},
"label" : "dummyLabel",
"campingEquipment" : {
"someKey" : "someValue"
}
},
"mountainRange" : {
"elevation" : "8000",
"temperature" : "50"
}
}
And my expected output JSON is:
{
"guests" : {
"amy" : "amy",
"theresa" : [ "Chef" ],
"jim" : [ "Bear Specialist" ],
"john" : [ "Tour Guide" ]
},
"dataSchema" : "dataSchema",
"data" : {
"key1" : "value1",
"key2" : {
"key3" : "value3",
},
"label" : "dummyLabel",
"campingEquipment" : {
"someKey" : "someValue"
}
},
"mountainRange" : {
"elevation" : "8000",
"temperature" : "50"
}
}
Notice that these fields were removed:
"heather" : [ "" ],
"brad" : [ "" ],
"thomas" : [ "" ],
"jane" : [ "" ]
Since they are empty strings in the arrays I do not want to include them in the resulting JSON object.
How would I construct a JOLT spec for this?
I tried this spec to remove the empty arrays.
[
{
"operation": "modify-overwrite-beta",
"spec": {
"guests": {
"theresa": "=recursivelySquashNulls",
"jim": "=recursivelySquashNulls",
"john": "=recursivelySquashNulls",
"heather": "=recursivelySquashNulls",
"brad": "=recursivelySquashNulls",
"thomas": "=recursivelySquashNulls",
"jane": "=recursivelySquashNulls"
}
}
},
{
"operation": "remove",
"spec": {
"guests": {
"theresa": "",
"jim": "",
"john": "",
"heather": "",
"brad": "",
"thomas": "",
"jane": ""
}
}
}
]
This did not work
and simply returned:
"guests" : {
"amy" : "amy"
},
It removed all the fields with empty arrays.
New contributor