I want to achieve the JSON transformation using the Jolt processor. I have fields with null in my JSON and I would like to remove all these fields...
{
"myValue": 345,
"colorValue": null,
"degreeDayValue": null,
"depthValue": null,
"distanceValue": null
}
...to just keep the myValue field.
Can I realize this with a Jolt operation removed?
To remove null values from the internal array use the below spec at the end of your code:
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=recursivelySquashNulls"
}
}
It is possible, just not straightforward. Requires two steps.
Spec::
[
{
"operation": "default",
"spec": {
// for all keys that have a null value
// replace that null value with a placeholder
"*": "PANTS"
}
},
{
"operation": "shift",
"spec": {
// match all keys
"*": {
// if the value of say "colorValue" is PANTS
// then, match but do nothing.
"PANTS": null,
// otherwise, any other values are ok
"*": {
// "recreate" the key and the non-PANTS value
// Write the value from 2 levels up the tree the "@1"
// to the key from 3 levels up the tree => "&2".
"@1": "&2"
}
}
}
}
]
Produces:
{
"myValue": 345
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With