Process JSON with jq
I grabbed some JSON using the Github API. I wanted to filter it with jq
The -C option of jq keeps the colour control codes and the -R option to less uses those codes..
List all the records in the JSON file:
jq -C '[.[]]' github_repos.json | less -R
List all the unique values for the visibility property:
jq '[.[] | .visibility] | unique' github_repos.json
List all the records where visibility is private:
jq -C '[.[] | select(.visibility == "private")]' github_repos.json | less -R
Sort the records by updated date (reversed):
jq -C 'sort_by(.updated_at) | reverse | [.[]]' github_repos.json | less -R
Sort the records where visibility is private by updated date (reversed):
jq -C 'sort_by(.updated_at) | reverse | [.[] | select(.visibility == "private")]' github_repos.json | less -R
Posted on .