0

如果找不到值,有没有办法抛出错误?

JSON:

{
  "qty": 2
}

数据格式: "order=" & order & ",qty=" & qty

如果order不在 JSON 中,将使用空值。如果值不存在,我想抛出一个错误,例如:

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

谢谢!

4

2 回答 2

0

$assert功能。

更多信息在这里:https ://github.com/jsonata-js/jsonata/issues/167

不幸的是,我没有找到它的 JSONata 文档。

于 2020-06-10T22:28:50.827 回答
0

有一个$error函数可以与该$exists函数一起使用来创建您自己的实现 if $not_empty。例如:

(
    $not_empty := function($val) { $exists($val) ? $val : $error("Missing!")};
    "order=" & $not_empty(order) & ",qty=" & qty
)
于 2020-06-12T06:20:36.207 回答