Recursive search values by key

后端 未结 2 555
长发绾君心
长发绾君心 2020-12-10 05:17

I have a JSON like this:

{ 
  \"A\": { \"error\": null },
  \"B\": { \"C\": {\"error\": \"error string\"}},
  \"C\": { \"D\": {\"error\": null}},
  \"D\": {          


        
2条回答
  •  無奈伤痛
    2020-12-10 06:17

    Use .. to iterate recursively, and get all the .error values. If they're null, remove them:

    jq '.. | .error? // empty'
    

    Alternatively, instead of using empty you can select the elements that are strings with strings:

    jq '.. | .error? | strings'
    

提交回复
热议问题