Manipulating a JSON file with jq

风格不统一 提交于 2019-12-06 05:50:25

Unfortunately you have not followed the guidelines at http://stackoverflow.com/help/mcve so it is difficult to tell from your description what output you are expecting, but the simplest way to delete a key from an object is to use del/1 as in the following:

.tracks
| map(select(.label=="cucumber_ChineseLong_v2.gff3") 
      | del(.maxHeight))

With your JSON as input, the result of the above query is rather long, so I won't include it in this response -- the "m" in "mcve" stands for "minimal".

Supplementary Q&A

Is it possible to return the original file with the 'maxHeight' removed?

For "editing" (as opposed to extraction), the trick is to use |=. There are many variations possible, for example:

.tracks |=
  map(if .label=="cucumber_ChineseLong_v2.gff3"
      then del(.maxHeight)
      else .
      end)

Some prefer the one-liner:

.tracks[] |= if .label=="cucumber_ChineseLong_v2.gff3" then del(.maxHeight) else . end
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!