MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 10 as of 2021-05-27 13:46:34
  • jq

jq

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

Slackbuild

   1 cd /tmp
   2 wget https://slackbuilds.org/slackbuilds/14.2/system/jq.tar.gz
   3 tar xvzf jq.tar.gz
   4 cd jq
   5 wget https://github.com/stedolan/jq/releases/download/jq-1.4/jq-1.4.tar.gz
   6 ./jq.SlackBuild
   7 installpkg /tmp/jq-1.4-i486-1_SBo.tgz
  • jq-1.4-i486-1_SBo.tgz

Change values

test.json

   1 {
   2   "keyx":12,
   3   "keyz":"ddff"
   4 }

test2.json

   1 {
   2   "keyx":12,
   3   "keyz":"ddff",
   4   "arr":[1,2,3,4]
   5 }

   1 jq '.keyx = 55 | .keyz = "otherVal"' test.json
   2 # output
   3 {
   4   "keyx": 55,
   5   "keyz": "otherVal"
   6 }

Get value from key

   1 jq '.keyx' test.json 
   2 # output
   3 12
   4 
   5 jq '.arr[2]' test2.json 
   6 #output
   7 3

Curl JSON replay example

* curl http://api.icndb.com/jokes/random 2>/dev/null | json_reformat

   1 {
   2     "type": "success",
   3     "value": {
   4         "id": 55,
   5         "joke": "Most people have 23 pairs of chromosomes. Chuck Norris has 72... and they're all poisonous.",
   6         "categories": [
   7 
   8         ]
   9     }
  10 }

   1 curl http://api.icndb.com/jokes/random 2>/dev/null | jq '.value.joke' | sed s/\"//g
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01