Created on 02-10-2022 10:16 AM - last edited on 02-10-2022 10:24 AM by DianaTorres
Hi,
I have the following Json. I would like to create a Jolt Spec to remove all nulls from all levels. How can I do that? Any help would be appreciated. Thanks
{
"ID": "c22b657e-227b-4c65-e6f8-08d88a3e1118",
"Name": "SomeName",
"TaggedItemName": "SomeValue",
"ITRName": "SomeValue",
"TestReference": null,
"JobCardName": null,
"Comments": "test",
"PrimaryHandoverName": null,
"SecondaryHandoverNumber": null,
"CertificationGroupingName": null,
"DocumentCode": "SomeValue",
"AssignedToName": "SomeName",
"DocumentReference": null,
"TagITRCompletionStatusName": "Rejected",
"ScheduleRevision": null,
"Completed": {
"SignOff_AuthP": "John",
"SignOff_Date": null
},
"Accepted": {
"SignOff_AuthP": "Smith",
"SignOff_Date": null
},
"Approved": {
"SignOff_AuthP": "Ali",
"SignOff_Date": null
},
"ScheduleGroup": null,
"DownloadUri": "SomeUrl",
"UpdatedDate": "2022-01-18T11:36:33.9057626Z",
"CreatedDate": "2020-11-30T10:57:20.8534287Z"
}
Created 02-11-2022 01:51 PM
Great to hear!
I try my best to understand Jolt because sometimes it can be quite useful, but I think it has a very convoluted syntax and sometimes it's really hard to use. But practice helps.
The first asterisk matches against the field names of an object. The second asterisk depends: if the value of the attribute is a scalar, it will match against the value; if it's a nest object, it will match against the name of the nested object. The trick is that when it matches the value of the object it does not match nulls 😉
Cheers,
André
Created 02-10-2022 06:45 PM
I don't know if it's possible to do this generically and recursively using Jolt.
Nevertheless, if your schema is well know you can achieve want you want with something like this:
{
"Completed": {
"*": {
"*": {
"@1": "&3.&2"
}
}
},
"Accepted": {
"*": {
"*": {
"@1": "&3.&2"
}
}
},
"Approved": {
"*": {
"*": {
"@1": "&3.&2"
}
}
},
"*": {
"*": {
"@1": "&2"
}
}
}
Cheers,
Andre
Created 02-11-2022 11:10 AM
Thank you so much,
That did the trick. You seem to be a json jolt guru. Im trying to understand it myself but its not that straight forward. Can you just elaborate this syntax for me which remove null values on the base level:
"*": {
"*": {
"@1": "&2"
}
}
Why there is two asterisks in front of it?
Created 02-11-2022 01:51 PM
Great to hear!
I try my best to understand Jolt because sometimes it can be quite useful, but I think it has a very convoluted syntax and sometimes it's really hard to use. But practice helps.
The first asterisk matches against the field names of an object. The second asterisk depends: if the value of the attribute is a scalar, it will match against the value; if it's a nest object, it will match against the name of the nested object. The trick is that when it matches the value of the object it does not match nulls 😉
Cheers,
André