Skip to main content
added 152 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

To delete the .packages.code key and its value, using jq:

jq 'del(.packages.code)' file.json

To delete any entry under .packages whose .name key has the value code:

jq 'del(.packages[] | select(.name == "code"))' file.json

The same two commands, but they take the code string from a shell variable:

string=code

jq --arg key "$string" 'del(.packages[$key])' file.json

jq --arg key "$string" 'del(.packages[] | select(.name == $key))' file.json

Redirect the output to a new file and replace the old file with that if it looks ok.

To delete the .packages.code key and its value, using jq:

jq 'del(.packages.code)' file.json

Redirect the output to a new file and replace the old file with that if it looks ok.

To delete the .packages.code key and its value, using jq:

jq 'del(.packages.code)' file.json

To delete any entry under .packages whose .name key has the value code:

jq 'del(.packages[] | select(.name == "code"))' file.json

The same two commands, but they take the code string from a shell variable:

string=code

jq --arg key "$string" 'del(.packages[$key])' file.json

jq --arg key "$string" 'del(.packages[] | select(.name == $key))' file.json

Redirect the output to a new file and replace the old file with that if it looks ok.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

To delete the .packages.code key and its value, using jq:

jq 'del(.packages.code)' file.json

Redirect the output to a new file and replace the old file with that if it looks ok.