Skip to content
Latchkey

gron: Make JSON Greppable for grep and diff

gron transforms JSON into a flat list of path = value; assignments, so you can grep and diff JSON without writing a jq filter.

When you do not know a JSON document's shape, gron is faster than guessing jq paths. Every leaf becomes one line you can grep, and the path it prints is the exact jq/JS path to that value.

What it does

gron reads JSON and emits one assignment per leaf, like json.users[0].name = "ada";. The left side is a valid access path, so once you grep the line you want, you know how to reach it in jq or JavaScript.

Common usage

Terminal
# flatten and grep for a field
curl -s https://api.example.com/u/1 | gron | grep email
# pipe a file and find every "id" path
gron data.json | grep '\.id ='
# stream large/NDJSON input
gron --stream events.json

Options

FlagWhat it does
-u, --ungronReverse: rebuild JSON from gron output
-s, --streamTreat input as a stream of JSON values
-j, --jsonRepresent output as JSON (for ungron round-trips)
-c, --colorizeForce colour output
--no-sortDo not sort output keys
-m, --monochromeDisable colour

In CI

gron makes API responses diffable: diff <(gron before.json) <(gron after.json) shows exactly which fields changed, which is far clearer than diffing pretty-printed JSON where reordering creates noise. Pair it with grep to assert a field exists in a smoke test.

Common errors in CI

gron: command not found means it is not installed; go install github.com/tomnomnom/gron@latest or grab a release binary. On invalid input gron prints failed to form statements: ... invalid character and exits non-zero, which is a useful guard that the upstream actually returned JSON and not an HTML error page. For NDJSON, plain gron errors on the second object; add --stream.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →