Avoiding null values in conditional output of array elements? #280
-
This question is along the lines of my other one but I can't quite seem to get the behaviour that I'm looking for when trying to copy values from source JSON to an array value in the target. The source has three name keys with string values that need to be conditionally copied to an array in the target.
Basically, the target array should either contain [ RC-GIVEN-NAME ] or [ RC-T1-GIVEN-NAME, RC-T12ND-GIVEN-NAME ] - if none of those fields exist, PersonGivenName in the output should be omitted. If any of the source values are null, the target array should not contain a null element (which is what I'm trying to solve right now). Current JSLT transform - note this does not address requirement (2) above, only (1):
This seems to work, except if T12ND-GIVEN-NAME is not present in the source, the output array contains a null: Source JSON example: RC-GIVEN-NAME not present, RC-T12ND-GIVEN-NAME not present
Expected output:
Actual output:
The 2nd expression Thank you! UPDATE: @larsga solution works for what I need and this is what I changed my transform to:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The easiest way to filter an array is to do
So you can do
Or you can declare a variable to make it a little easier to see what's going on. |
Beta Was this translation helpful? Give feedback.
The easiest way to filter an array is to do
So you can do
Or you can declare a variable to make it a little easier to see what's going on.