Skip to content

Avoiding null values in conditional output of array elements? #280

Answered by larsga
digitalfiends asked this question in Q&A
Discussion options

You must be logged in to vote

The easiest way to filter an array is to do

[for (<array>) . if (.)]

So you can do

{
    "Client": {

        "PersonName": {
            "PersonGivenName": [for ([
                fallback(.RC-INPUT-DTL-REC.RC-GIVEN-NAME, .RC-INPUT-DTL-REC.RC-T1-GIVEN-NAME),
                if(not(.RC-INPUT-DTL-REC.RC-GIVEN-NAME) and .RC-INPUT-DTL-REC.RC-T12ND-GIVEN-NAME)
                  .RC-INPUT-DTL-REC.RC-T12ND-GIVEN-NAME
            ]) . if (.)]
       }
    }
}

Or you can declare a variable to make it a little easier to see what's going on.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@digitalfiends
Comment options

Answer selected by digitalfiends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
support Users asking how to solve a specific issue
2 participants