The examples in this topic use the following data model.

{
  "user": {
    "name": {
      "given": "John",
      "family": "Doe"
    }
}

String concatenation

Issue

Because user.name.middle is null, the expression user.name.given + ', ' + user.name.middle + ', ' + user.name.family returns John, null, Doe.

Solution to concatenate only non-null values

#string.join({user.name.given, user.name.middle, user.name.family}, ', ') returns John, Doe.

Issue

Because user.age is null and the other operand is numeric, the expression 3 + user.age returns an error.

Solution to avoid errors using an Elvis operator to add a default value

3 + (user.age ?: '') returns 3.

Creating an array using nullable values

Issue

The newly created array {user.externalId} returns [ null ].

Solution to remove nulls from the newly created array

#data.removeAll({user.externalId}, {null}) returns [].

Ternary operator

Issue

Because user.enabled is null, the expression user.enabled ? 'Active' : 'Inactive' returns an error.

Solution to avoid errors using an Elvis operator to add a default value

(user.enabled ?: false) ? 'Active' : 'Inactive' returns Inactive.