https://github.com/trananhtung/gron-rs
Make JSON greppable: flatten JSON to assignment lines and back (a Rust gron/ungron), library + CLI.
https://github.com/trananhtung/gron-rs
cli flatten grep gron jq json rust
Last synced: 3 days ago
JSON representation
Make JSON greppable: flatten JSON to assignment lines and back (a Rust gron/ungron), library + CLI.
- Host: GitHub
- URL: https://github.com/trananhtung/gron-rs
- Owner: trananhtung
- License: apache-2.0
- Created: 2026-06-21T10:39:24.000Z (9 days ago)
- Default Branch: main
- Last Pushed: 2026-06-22T14:46:19.000Z (8 days ago)
- Last Synced: 2026-06-22T16:16:46.943Z (8 days ago)
- Topics: cli, flatten, grep, gron, jq, json, rust
- Language: Rust
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# gron-rs
[](#contributors-)
[](https://crates.io/crates/gron-rs)
[](https://docs.rs/gron-rs)
[](https://github.com/trananhtung/gron-rs/actions/workflows/ci.yml)
[](#license)
**Make JSON greppable.** Flatten a JSON document into discrete assignment lines
you can `grep`, `diff`, and `sed` — then turn them back into JSON. A Rust port of
[gron](https://github.com/tomnomnom/gron), available as both a **library** and a
`gron` **CLI**.
```text
$ echo '{"user":{"name":"Tom","tags":["a","b"]}}' | gron
json = {};
json.user = {};
json.user.name = "Tom";
json.user.tags = [];
json.user.tags[0] = "a";
json.user.tags[1] = "b";
$ echo '{"user":{"name":"Tom"}}' | gron | grep name
json.user.name = "Tom";
$ gron file.json | grep '\.user' | gron --ungron # filter, then rebuild JSON
```
## Why gron-rs?
`gron` makes deeply-nested JSON diffable and greppable — but Rust's existing gron
crates are all stale (2017–2022), one-way, or CLI-only with **no library API**.
`gron-rs` is a maintained, round-trip (`gron` + `ungron`) implementation you can
use both ways.
## Library
```toml
[dependencies]
gron-rs = "0.1"
```
```rust
use serde_json::json;
let v = json!({ "name": "Tom", "tags": ["a", "b"] });
let lines = gron::gron(&v); // flatten
let back = gron::ungron(&lines).unwrap(); // reconstruct
assert_eq!(back, v);
```
| Function | Purpose |
| --- | --- |
| `gron(&Value) -> String` | Flatten to assignment lines (root `json`) |
| `gron_with_root(&Value, root) -> String` | Flatten with a custom root identifier |
| `ungron(&str) -> Result` | Reconstruct JSON from gron lines |
## CLI
```sh
cargo install gron-rs # installs the `gron` binary
gron file.json # flatten (or pipe via stdin)
gron -u # --ungron: reconstruct JSON from stdin
gron --root data file.json # custom root identifier
```
## Behavior
- Object keys that are valid identifiers use `.key`; others are `["quoted"]`.
- Output is in structural order (objects by sorted key, arrays by index) —
stable and diff-friendly.
- `ungron` reconstructs containers even if the empty-container lines are missing
(inferred from the paths), and round-trips any `gron` output exactly.
## Contributors ✨
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
## License
Licensed under either of [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) at
your option.