Make JSON greppable!
Go PHP Shell
Failed to load latest commit information.
script Switches windows binary package to zip Jul 3, 2016
testdata Adds .UseNumber() to JSON decoding; fixes #6 Jul 4, 2016
.gitignore Switches windows binary package to zip Jul 3, 2016
.travis.yml Adds license, travis.yml Jun 4, 2016
ADVANCED.mkd Switches to double quotes in examples; fixes #5 Jul 3, 2016
CHANGELOG.mkd Adds .UseNumber() to JSON decoding; fixes #6 Jul 4, 2016
CONTRIBUTING.mkd Adds changelog, update contributing Jun 5, 2016
LICENSE Adds license, travis.yml Jun 4, 2016
identifier.go Moves reserved word list to a map for faster lookup Jun 22, 2016
identifier_test.go Moves identifier related code into new files Jun 22, 2016
main.go Adds .UseNumber() to JSON decoding; fixes #6 Jul 4, 2016
statements.go Adds .UseNumber() to JSON decoding; fixes #6 Jul 4, 2016
statements_test.go Adds .UseNumber() to JSON decoding; fixes #6 Jul 4, 2016
ungron.go Fixes bug with values containing semicolons; adds advanced doc Jun 30, 2016
url.go Refactors ungron main, updates help and readme Jun 30, 2016



Build Status

Make JSON greppable!

gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it. It eases the exploration of APIs that return large blobs of JSON but have terrible documentation.

gron "" | fgrep ""
json[0] = {};
json[0] = "2016-07-02T10:51:21Z";
json[0] = "";
json[0] = "Tom Hudson";

gron can work backwards too, enabling you to turn your filtered data back into JSON:

▶ gron "" | fgrep "" | gron --ungron
    "commit": {
      "author": {
        "date": "2016-07-02T10:51:21Z",
        "email": "",
        "name": "Tom Hudson"

Disclaimer: the GitHub API has fantastic documentation, but it makes for a good example.


gron has no runtime dependencies. You can just download a binary for Linux, Mac or Windows and run it. Put the binary in your $PATH (e.g. in /usr/bin) to make it easy to use:

▶ tar xzf gron-linux-amd64-0.1.5.tgz
▶ sudo mv gron /usr/bin/

Or if you're a Go user you can use go get:

▶ go get -u

It's recommended that you alias ungron or norg (or both!) to gron --ungron. Put something like this in your shell profile (e.g. in ~/.bashrc):

alias norg="gron --ungron"
alias ungron="gron --ungron"


Get JSON from a file:

▶ gron testdata/two.json 
json = {}; = {}; = ""; = "@TomNomNom";
json.github = "";
json.likes = [];
json.likes[0] = "code";
json.likes[1] = "cheese";
json.likes[2] = "meat"; = "Tom";

From a URL:

▶ gron
json = {};
json.Host = "";
json["User-Agent"] = "gron/0.1";
json["X-Cloud-Trace-Context"] = "6917a823919477919dbc1523584ba25d/11970839830843610056";

Or from stdin:

▶ curl -s | gron
json = {};
json.Accept = "*/*";
json.Host = "";
json["User-Agent"] = "curl/7.43.0";
json["X-Cloud-Trace-Context"] = "c70f7bf26661c67d0b9f2cde6f295319/13941186890243645147";

Grep for something and easily see the path to it:

▶ gron testdata/two.json | grep twitter = "@TomNomNom";

The output of gron is valid JavaScript:

▶ gron testdata/two.json > tmp.js
▶ echo "console.log(json);" >> tmp.js
▶ nodejs tmp.js
{ contact: { email: '', twitter: '@TomNomNom' },
  github: '',
  likes: [ 'code', 'cheese', 'meat' ],
  name: 'Tom' }


gron can also turn its output back into JSON:

▶ gron testdata/two.json | gron -u
  "contact": {
    "email": "",
    "twitter": "@TomNomNom"
  "github": "",
  "likes": [
  "name": "Tom"

This means you use can use gron with grep and other tools to modify JSON:

▶ gron testdata/two.json | grep likes | gron --ungron
  "likes": [

To preserve array keys, arrays are padded with null when values are missing:

▶ gron testdata/two.json | grep likes | grep -v cheese
json.likes = [];
json.likes[0] = "code";
json.likes[2] = "meat";
▶ gron testdata/two.json | grep likes | grep -v cheese | gron --ungron
  "likes": [

If you get creative you can do some pretty neat tricks with gron, and then ungron the output back into JSON.

Get Help

▶ gron --help
Transform JSON (from a file, URL, or stdin) into discrete assignments to make it greppable

  gron [OPTIONS] [FILE|URL|-]

  -u, --ungron  Reverse the operation (turn assignments back into JSON)

Exit Codes:
  0 OK
  1 Failed to open file
  2 Failed to read input
  3 Failed to form statements
  4 Failed to fetch URL
  5 Failed to parse statements
  6 Failed to encode JSON

  gron /tmp/apiresponse.json
  curl -s | gron
  gron | grep company | gron --ungron


Wasn't this written in PHP before?

Yes it was! The original version is preserved here for posterity.

Why the change to Go?

Mostly to remove PHP as a dependency. There's a lot of people who work with JSON who don't have PHP installed.

Why shouldn't I just use jq?

jq is awesome, and a lot more powerful than gron, but with that power comes complexity. gron aims to make it easier to use the tools you already know, like grep and sed.

gron's primary purpose is to make it easy to find the path to a value in a deeply nested JSON blob when you don't already know the structure; much of jq's power is unlocked only once you know that structure.