Gron's purpose is to turn JSON into grep-able, but still valid, JavaScript.
Gron is written in PHP. It requires PHP 5.2 or newer.
Pipe JSON into Gron's stdin:
~# cat test-input.json | ./gron
json = {};
json["one"] = 1;
json["two"] = 2;
json["three-b"] = "3";
json["four"] = [];
json["four"][0] = 1;
json["four"][1] = 2;
json["four"][2] = 3;
json["four"][3] = 4;
json["five"] = {};
json["five"]["alpha"] = [];
json["five"]["alpha"][0] = "fo";
json["five"]["alpha"][1] = "fum";
json["five"]["beta"] = {};
json["five"]["beta"]["hey"] = "How's tricks?";
The idea is that you can grep the result to find what you're looking for, and where it exists in the JSON structure:
~# cat test-input.json | ./gron | grep tricks
json["five"]["beta"]["hey"] = "How's tricks?";
This is useful when exploring unfamiliar APIs that have large responses but lacklustre documentation.
Gron can also fetch JSON straight from files:
~# ./gron test-input.json | grep tricks
json["five"]["alpha"][1] = "fum";
Or from URLs:
~# ./gron http://api.tomnomnom.com/crypto/blowfish/randomsalt
json = {};
json["salt"] = "$2a$11$6rm6zQm3DaQQqZYjXerBjf";
Gron's exit code depends on what happened:
0 - Success
1 - Failed to decode JSON
2 - Argument is not valid file or URL
3 - Failed to fetch data from URL
Put Gron in your $PATH
(e.g. /usr/bin/gron
) so you don't have to use the "./":
~# sudo mv gron /usr/bin/gron
~# cat test-input.json | gron
Instead of:
~# cat test-input.json | ./gron