嵌套键中的jq特殊字符 [英] jq special characters in nested keys
问题描述
我有一个类似于以下内容的json:
I have a json similar to the following:
{
"_source" : {
"index-pattern" : {
"fields" : ""
}
}
}
我正在尝试修改字段,但链接了.身份运算符,例如'jq ._source.["index-pattern"].fields
'会产生以下错误:
I'm trying to modify fields, but chaining the . identity operator, such as 'jq ._source.["index-pattern"].fields
' produces the following error:
'._source.["index-pattern"]
^
1 compile error'
有什么想法吗?
谢谢
推荐答案
您可以这样写:
._source | .["index-pattern"].fields
甚至:
._source["index-pattern"].fields
说明:如果"x"和"y"表示是以字母字符(其中字母"包括"_")开头的字母数字字符串,则.x | .y
可以缩写为.x.y
.
Explanation: if "x" and "y" are alphanumeric strings that begin with an alphabetic character (where "alphabetic" includes "_") then .x | .y
can be abbreviated to .x.y
.
在其他几种情况下,可以缩写E | F
,例如E | .[]
通常可以缩写为E[]
.
There are several other circumstances when E | F
can be abbreviated, e.g. E | .[]
can often be abbreviated to E[]
.
但是,一般规则是:
如果缩写形式不起作用,请不要使用它.
If an abbreviated form does not work, don't use it.
这篇关于嵌套键中的jq特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!