Home > Blockchain >  Is there a way to filter a JSON list with jq and remove an attribute from the filtered results with
Is there a way to filter a JSON list with jq and remove an attribute from the filtered results with

Time:08-31

Figured this line works, but uses jq twice:

cat file.json | jq -c '.[] | select(.property=="undesired")' | jq -c 'del(.property)'

Is there a way to invoke jq just once?

CodePudding user response:

Just pipe the filters together within a single jq command:

jq -c '.[] | select(. property=="undesired") | del(.property)' file.json
  • Related