cancel
Showing results for 
Search instead for 
Did you mean: 

Remove emply/null value fields from JSON

rajeshramasamy
New Contributor

Can you help me to remove empty/null value fields from a JSON structure? Kindly suggest pipeline design suggestion or expression language for the below expected results. Thanks!

Input:
{
“INVOICE”: {
“TITLE”: “Test”,
“DESCRIPTION”: “Test124”,
“VERSION”: “”,
“IRN”: “”,
“TRANDTLS”: {
“TAXSCH”: “”,
“SUPTYP”: “B2B”,
“REGREV”: “”,
“IGSTONINTRA”: “N”
},
“NOTES”: {
“ID”: “”,
“TEXT”: “”
}
}
}

Expected Output
{
“INVOICE”: {
“TITLE”: “Test”,
“DESCRIPTION”: “Test124”,
“TRANDTLS”: {
“SUPTYP”: “B2B”,
“IGSTONINTRA”: “N”
}
}
}

1 REPLY 1

rvsrinivasrao
Employee
Employee

Hi Rajesh,

Use JSONPath to remove any keys where the values are empty/null as follows: jsonPath($,“$…[?(value == null) || (value == “”)]”)
In a mapper, put this in the expression field and leave the target field blank. Click on Pass Through.

image

The response is

image

Please find the attached pipeline.

Remove_Empty_Null_Values_2020_12_03.slp (4.9 KB)