【发布时间】:2019-05-01 06:59:29
【问题描述】:
jq docs 中的以下示例按预期工作 --
$ echo '[1,2]' | jq 'map(in([0,1]))'
[
true,
false
]
但将值转换为字符串失败 -
$ echo '["1", "2"]' | jq 'map(in(["0","1"]))'
jq: error (at <stdin>:1): Cannot check whether array has a string key
为了确保这不是 shell 引用问题,我还尝试了 --
$ echo "[\"1\", \"2\"]" | jq 'map(in(["0","1"]))'
jq: error (at <stdin>:1): Cannot check whether array has a string key
此外,以下 sn-p 也失败了,这可能是由于将 0 转换为布尔值 false -
$ echo '[0,1]' | jq 'map(in([1,2]))'
[
true,
true
]
【问题讨论】: