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.