GoJSON is a command line utility to handle json in command line.
- Retrieve nested objects
- Pretty print JSON
- Validate JSON
- Aggregate functions
Go Dev version
$ go get -u github.com/sarathsp06/gojson
Binray Release
download and use the binary as such for your platform
Tip:
In unix move the binary to PATH
- Key is a set of
.
seperated nested values - Can use 0-n numbers to refer to index in arrays
- Can use
lower:upper
syntax to refer to a range of an array. Eg: players.1:3 - Can use keys of inner objects directly on arrays or range of them. Eg: players.name where players is an array
- 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"
- Projection from a slice
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:.name
[
"singh",
"ping"
]
- Slice of array
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:5
[
{
"name": "singh"
},
{
"name": "ping"
}
]