Search code examples
jsonata

How to throw an error if value not found in JSON (JSONata)


Is there way to throw an error if value not found?

JSON:

{
  "qty": 2
}

JSONata: "order=" & order & ",qty=" & qty

If order is not in JSON, empty value will be used. I would like to throw an error if value not exist, for example something like this:

"order=" & $not_empty(order) & ",qty=" & qty

Thanks!


Solution

  • there is $assert function.

    more info here: https://github.com/jsonata-js/jsonata/issues/167

    unfortunately I did not found it JSONata documentation.