Post

Linux filter json using jq

Linux filter json using jq

jq is the tool that makes working with JSON in shell scripts actually pleasant. I use it constantly for parsing API responses, extracting specific fields from config files, and pretty-printing JSON that comes back as a single minified line. If you’re not using it yet, install it now.

  • Print json
1
2
3
4
5
6
$ echo '{"bla":"bla"}' | jq '.'

{
  "bla": "bla"
}

  • Filter json
1
2
3
4
5
$ echo '{"bla":"bla","blaa":"blaa"}' | jq '{"bla"}'

{
  "bla": "bla"
}
This post is licensed under CC BY 4.0 by the author.