jq special characters in nested keys

随声附和 提交于 2020-01-10 06:07:30

问题


I have a json similar to the following:

{
    "_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'

Any ideas?

thanks


回答1:


You could write:

._source | .["index-pattern"].fields

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.

There are several other circumstances when E | F can be abbreviated, e.g. E | .[] can often be abbreviated to E[]. The general rule is:

If an abbreviated form does not work, don't use it.



来源:https://stackoverflow.com/questions/48450533/jq-special-characters-in-nested-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!