Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 9, 2016 00:46
Show Gist options
  • Save nepsilon/d3eb3731a0049d3b7777 to your computer and use it in GitHub Desktop.
Save nepsilon/d3eb3731a0049d3b7777 to your computer and use it in GitHub Desktop.
CLI JSON processor with jq — First published in fullweb.io issue #22

CLI JSON processor with jq

Let’s talk about jq, the command line JSON processor.

jq works the UNIX way, and can use it the same way you use sed, grep and the likes. It is very flexible and supports a lot of options, be sure to check it’s documentation.

Here are 2 simple examples to give you an idea:

1. Piping JSON to jq:

. denotes the root of the JSON, here we return the first element of the root array

... | jq '.[0]' 

2. Filtering keys:

Only keep some keys id, message.author:

... | jq '.[0] | {id, message.author}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment