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.
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.
12-22-2017 10:27 AM
Thank you so much. It worked by creating an empty $array[*].subArray. Do you know where I can learn more about the syntax to use to manipulate JSON like this? I get stuck and spin my wheels a lot on these types of issues.
Also, is there a way to delete just a simple field, not an array/list, with the Mapper if its null like the above expression did for the array? When the right Target path is empty, I’m not sure what expression to use on the left to return the field when its null.
12-22-2017 02:45 PM
We have our own documentation for JSON-Path. There are also online testers, like:
Note that most JSON-Path implementations are only for reading data, whereas we use it for updating and deletions. So,
In the Designer, you should be able to drill down into the document structure in the Mapper and in the drop-down for expression properties.
It’s pretty much the same thing, except instead of checking for value.field1 == null
you can check if value == null
. So, you would write a path to the object whose fields you want to delete (e.g. $.foo.bar
) and then use the filter operator ([?(... expr ...)]
) to select the fields to delete:
$.foo.bar[?(value == null)]
03-06-2019 07:19 AM
If I have the following in a JSON Generator and a subsequent Mapper, what do I put in the Expression to remove “id” field if its null? I’m getting a parsing error when trying $.id[?(value == null)].
[
{
“id”: 21,
“eId”: [
256,
2,
548,
14010
]
},
{
“id”: null,
“eId”: [
256,
2,
548,
14010
]
}
]