jq 可以将 has() 与嵌套键一起使用吗?

art*_*lay 5 nested key jq

是否可以将 jq has() 函数与嵌套键一起使用

jq -r -c 'has("a.b")' <<< '{"a":{"b":"hello"}}'
Run Code Online (Sandbox Code Playgroud)

这返回为 false,我也尝试过

has("a|b")
has("a[b]")
Run Code Online (Sandbox Code Playgroud)

pmf*_*pmf 2

不直接,但您可以下降到该级别,并用于has最后一个:

jq '(.a | has("b"))' <<< '{"a":{"b":"hello"}}'
Run Code Online (Sandbox Code Playgroud)

或者,搜索paths您要查找的内容,并将其转换为数组表示法:

jq 'IN(paths; ["a","b"])' <<< '{"a":{"b":"hello"}}'
Run Code Online (Sandbox Code Playgroud)