I'm looking for tool which would allow me to parse JSON from a pipeline. Like converting it to some other common formats which are easier to parse or sort or to retrieve certain elements (like XPath).
2 Answers
This "json" tool I found is very flexible.
json
is a fast CLI tool for working with JSON. It is a single-file node.js script with no external deps (other than node.js itself).
Example usage:
$ echo '{"foo":"bar"}' | json foo
bar
$ echo '{"fred":{"age":42}}' | json fred.age # '.' for property access
42
$ echo '{"age":10}' | json -e 'this.age++'
{
"age": 11
}
Docs/features at http://trentm.com/json/
A list of alternative tools is also given at the bottom which are:
- jq: http://stedolan.github.io/jq/
- json:select: http://jsonselect.org/
- json-command: https://github.com/zpoley/json-command
- JSONPath: http://goessner.net/articles/JsonPath/, http://code.google.com/p/jsonpath/wiki/Javascript
- jsawk: https://github.com/micha/jsawk
- jshon: http://kmkeen.com/jshon/
- json2: https://github.com/vi/json2
-
Can you add some information about why this would be a good tool for the OP - especially if the conversion is possible? We like more than just link-only answers on SE sites. Thanks.– user416Feb 9, 2017 at 21:24
You can use pythons supplied JSON Library to parse into python objects and then output in a variety of other formats also supported either by the python library or by additional libraries. These include XML/xpath.