JSON filter tool
json
takes input from stdin
and pretty-prints to stdout
. With no arguments it behaves like python -mjson.tool
.
When given arguments, each argument is either a field selector or a filter.
echo '{ "a": { "b": "c"} }' | json a
selects the field a and prints {"b": "c"}
echo '{ "a": [{ "b": "c"}, {"b": "d"}] }' | json a b=d b
does the following:
- select the field
a
- filter by
b=d
- select the field
b
and finally prints ["d"]
curl http://v11.cat.api.dev.streamco.com.au/feeds/programs.json | json entries 'classifications.0.consumerAdvice.0=strong language' title,url
plucks the URL and title of all programs the first consumerAdvice equalling 'strong language' (you can use a regex with ~ instead of =). null
s are gracefully skipped, etc.
[
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0044706.json",
"title": "High Noon (1952)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0040746.json",
"title": "Rope (1948)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0107290.json",
"title": "Jurassic Park (1993)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0103064.json",
"title": "Terminator 2: Judgment Day (1991)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0046359.json",
"title": "Stalag 17 (1953)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0993846.json",
"title": "The Wolf of Wall Street (2013)"
},
{
"url": "http://v11.cat.api.dev.streamco.com.au/programs/tt0167404.json",
"title": "The Sixth Sense (1999)"
}
]