= jq =
jq is a lightweight and flexible command-line JSON processor.

== Slackbuild ==
{{{#!highlight bash
cd /tmp
wget https://slackbuilds.org/slackbuilds/14.2/system/jq.tar.gz
tar xvzf jq.tar.gz
cd jq
wget https://github.com/stedolan/jq/releases/download/jq-1.4/jq-1.4.tar.gz
./jq.SlackBuild
installpkg /tmp/jq-1.4-i486-1_SBo.tgz
}}}
 * [[attachment:jq-1.4-i486-1_SBo.tgz]]

== Change values ==

'''test.json'''
{{{#!highlight javascript
{
  "keyx":12,
  "keyz":"ddff"
}
}}}

'''test2.json'''
{{{#!highlight javascript
{
  "keyx":12,
  "keyz":"ddff",
  "arr":[1,2,3,4]
}
}}}

{{{#!highlight bash 
jq '.keyx = 55 | .keyz = "otherVal"' test.json
# output
{
  "keyx": 55,
  "keyz": "otherVal"
}
}}}

== Get value from key ==
{{{#!highlight bash 
jq '.keyx' test.json 
# output
12

jq '.arr[2]' test2.json 
#output
3
}}}

== Curl JSON replay example ==
* curl http://api.icndb.com/jokes/random 2>/dev/null | json_reformat 
{{{#!highlight javascript
{
    "type": "success",
    "value": {
        "id": 55,
        "joke": "Most people have 23 pairs of chromosomes. Chuck Norris has 72... and they're all poisonous.",
        "categories": [

        ]
    }
}
}}}

{{{#!highlight bash
curl http://api.icndb.com/jokes/random 2>/dev/null | jq '.value.joke' | sed s/\"//g
curl https://www.tronalddump.io/random/quote 2>/dev/null | jq ".value" | sed s/\"//g
}}}