12-21-2017 03:11 PM
If I have the following,
[{
"fieldType": null,
"array": [{
"fieldA": null,
"subArray": [{
"field1": null
}]
}]
},
{
"fieldType": null,
"array": [{
"fieldA": null,
"subArray": [{
"field1": 1,
"field2": "asdf",
"field3": "fdff"
}]
}]
}]
how do I set the subArray with field1 = null to an empty array or completely remove subArray like the following:
– EMPTY ARRAY
[{ "fieldType": null, "array": [{ "fieldA": null, "subArray": [] }] }, { "fieldType": null, "array": [{ "fieldA": null, "subArray": [{ "field1": 1, "field2": "asdf", "field3": "fdff" }] }] }]
OR
– DELETE ARRAY
[{ "fieldType": null, "array": [{ "fieldA": null }] }, { "fieldType": null, "array": [{ "fieldA": null, "subArray": [{ "field1": 1, "field2": "asdf", "field3": "fdff" }] }] }]
Solved! Go to Solution.
12-21-2017 04:21 PM
You might want to look at this post that had a similar request.
In short, you can use a Mapper with a JSON-Path in the left field of a mapping row with an empty right field to delete all elements on the path. In this case, you’d probably use a path like the following:
$array[*].subArray[?(value.field1 == null)]
Make sure you have the ‘Passthrough’ option enabled in the Mapper.
03-06-2019 07:39 AM
Currently, in order to use the [?(...)]
syntax in a JSON-Path, the previous part of the path needs to refer to an array or object. (Although I feel like your attempt makes sense and should have worked.)
To delete a property from an object, you need to filter the object and test for the property name and value, like so:
$[?(key == 'id' && value == null)]
03-06-2019 10:17 AM
Thank you! That’s what I was hoping wasn’t the case. I opened a Support ticket for it and another issue I’m having filtering an array as documented.
12-13-2019 06:16 AM
Hi kmiesse,
Was an solution provided to this? I am still facing the issue while trying to filter a key whose value is null
11-04-2020 06:35 AM
Thank you tstack for the answer to a problem I was facing. I was able to remove nulls and dashes across a document using this a mapper: $.[?(value == ‘-’ || value == null)]
My inbound document looked like this:
[
{
“TRANSACTION”: “32”,
“DATE_OF_BIRTH”: “1995-09-21”,
“SSN”: null,
“BOX_OR_RESIDENCE”: “-”,
“PRONOUN_DESC”: “-”,
“AUDIT_ONLY”: “N”,
“HOME”: “Y”,
“HOME_SUPPRESSION”: “tbd”
}
]