Terminal: CURL | walk to JsonPath | pretty json

I am looking for an opportunity to print parts of a returned JSON document in a wrapper.

Right now, I am passing an HTTP response from cURL to python to print it:

curl -vX GET http://foo.bar | python -mjson.tool

But now I would like to know how I could β€œgo through” the path to a subarray?

If, for example, JSON data was returned:

{
"value1": true,
"value2": {
            "subvalue1": "foo",
            "subvalue2": "bar"
          }
}

How can I print only subarms in this example?

+5
source share
1 answer

Terry Jones wrote a good tool for this just a few months ago. Here is his blog post about this http://blogs.fluidinfo.com/terry/2010/11/25/jsongrep-py-python-for-extracting-pieces-of-json-objects/ .

,

curl -vX GET http://foo.bar | jsongrep.py value2

, , JSON. Subarray ( - JSON)

{
   "subvalue1": "foo",
   "subvalue2": "bar"
}
+2

All Articles