jq - select objects with given key name

前端 未结 3 683
渐次进展
渐次进展 2021-02-01 22:38

I\'ve got an arbitrary structure with many levels, etc. I need to select all objects that contain a key named updateDate. How do I do that with jq? I came up with o

3条回答
  •  耶瑟儿~
    2021-02-01 23:23

    In 1.4 you can just:

    jq '..|.updateDate?'
    

    If you're stuck with 1.3 you can use a longer program like so:

    jq 'recurse(if type == "array" or type = "object" then .[] else empty end) | if type == "object" then .updateDate else empty end'
    

提交回复
热议问题