Using json in bash :

  • jsawk : work with an array of JSON objects read from stdin, filter them using JavaScript to produce a results array that is printed to stdout. For example get’s json ( from Yahoo image search by ‘madonna’ query ) and add some info ( madonna’s real name ) to this
  • wget http://bokov.net/json_example.json
    cat json_example.json | ./jsawk "this.ResultSet.RealName=\"Louise Ciccone\"" > updated_info.json

  • you can use some bash/awk/sed stuff to parse json. For example – list all image urls from json
  • wget http://bokov.net/json_example.json
    cat json_example.json | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"ClickUrl":' | sed 's/:/ /1' | awk -F" " '{ print $2 }'

  • or use library from json.org for language which you like :-)

via v.kruchkov

Leave a Reply