Manipulate JSON in bash

Solution 1:

a quick experiment:

$ echo '{
  "Comment": "comment",
  "test": {
    "enabled": true
   },
  "enabled": true,
  "otherStuff": "blah",
  "otherStuff2": "blah",
  "otherStuff3": "blah"
}' |
jq '.enabled=false'
{
  "otherStuff3": "blah",
  "otherStuff2": "blah",
  "otherStuff": "blah",
  "enabled": false,
  "test": {
    "enabled": true
  },
  "Comment": "comment"
}

Solution 2:

I read the question as "in the shell" and not necessarily as "using only bash builtins".

Try jsawk, which allows for manipulation and is scriptable, thought it relies on js as a dependency.

If all you want to do is read a (unique) key from the JSON response, you could (adapted from Brendan OConnor):

curl <destination> | grep -Po '"keyname":.*?[^\\]",'`