GoJSON is a command line utility to handle json in command line.
- Retrieve nested objects
- Pretty print JSON
- Validate JSON
- Aggregate finct
With go
$ go get -u github.com/sarathsp06/gojson
Or you may download the binary here download and use the binary as such
Tip:
In unix move the binary to PATH
- Key is a set of
.
seperated nested keys - Can use 0-n numbers to refer to index in arrays
- Get a string:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson name.last
"Pillai"
- Get a block of JSON:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson name
{
"first": "Sarath",
"last": "Pillai"
}
- Try to get a non-existent key:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson names
nil
Get an array value by index:
$ echo '{"people":[{"name":"saratha"},{"name":"syam"}]}' | gojson people.1.name
"syam"