使用 Jsonata 匹配名称包含空格或特殊字符的 json 字段
Matching a json field with a name that contains spaces or special charecters with Jsonata
假设我有一些 JSON 比如:
{
"normal": 1,
"has some spaces": 2,
"@": 3
}
我可以通过简单查询获取 normal
字段的值:
normal
但是我无法获取其他两个字段。我试过:
[has some spaces]
'has some spaces'
['has some spaces']
"has some spaces"
["has some spaces"]
{has some spaces}
{'has some spaces'}
{"has some spaces"}
但其中 none 有效
维护者在 github issue I raised :
上为我解决了这个问题
Under the Navigating JSON Objects section, the following is listed:
Field references containing whitespace or reserved tokens can be enclosed in backticks
...
then the JSONata expressions `has some spaces`
and `@`
will match 2 and 3 respectively.
但在我通过反复试验发现两个替代方案之前:
$."has some spaces"
和
$.'has some spaces'
假设我有一些 JSON 比如:
{
"normal": 1,
"has some spaces": 2,
"@": 3
}
我可以通过简单查询获取 normal
字段的值:
normal
但是我无法获取其他两个字段。我试过:
[has some spaces]
'has some spaces'
['has some spaces']
"has some spaces"
["has some spaces"]
{has some spaces}
{'has some spaces'}
{"has some spaces"}
但其中 none 有效
维护者在 github issue I raised :
上为我解决了这个问题Under the Navigating JSON Objects section, the following is listed:
Field references containing whitespace or reserved tokens can be enclosed in backticks
...
then the JSONata expressions
`has some spaces`
and`@`
will match 2 and 3 respectively.
但在我通过反复试验发现两个替代方案之前:
$."has some spaces"
和
$.'has some spaces'