gitmyhub

gron

Go ★ 14k updated 1y ago

Make JSON greppable!

Gron is a command-line tool that flattens JSON into one line per value with full key paths so you can search nested API responses with grep, then reconstruct valid JSON from the filtered lines with --ungron.

Gosetup: easycomplexity 1/5

Gron is a small command-line tool that reformats JSON data into a flat list of simple statements, where each line shows the full path to a single value. JSON is a common format that web services use to return data, but deeply nested JSON can be hard to search through by hand. Gron solves that by flattening the structure so that standard search tools like grep can work on it naturally.

For example, if you fetch data from a web API and pipe it through gron, instead of seeing a complex nested structure, you get one line per value such as: json.user.name = "Alice"; or json.results[0].score = 42;. You can then search for any keyword and immediately see not just the value but the full path of keys and indexes needed to reach it.

Gron also works in reverse. If you filter the flattened output down to only the lines you care about and then run it again with the --ungron flag, it reconstructs valid JSON from just those lines. This makes it practical to extract specific pieces of a large JSON response without writing any code or learning a query language.

The tool accepts input from a file, a URL, or piped data from another program. It has no runtime dependencies, so installation is just downloading a single binary for your operating system (Linux, Mac, Windows, or FreeBSD) and putting it somewhere on your path. Mac users can also install it through the Homebrew package manager.

Gron is written in Go and is intentionally simple in scope. Its README notes that more powerful JSON query tools exist, but gron's goal is to let you use search and text tools you already know rather than learning a new query syntax. It is open source and has no license file listed in the README, though it has been widely adopted in developer workflows.

Where it fits