Skip to main content

Crate gron

Crate gron 

Source
Expand description

§gron — make JSON greppable

Flatten a JSON document into discrete, greppable assignment lines, and reconstruct it back — a Rust port of gron, available both as a library and a gron CLI.

use serde_json::json;

let v = json!({ "user": { "name": "Tom", "tags": ["a", "b"] } });
let lines = gron::gron(&v);
assert_eq!(lines, "\
json = {};
json.user = {};
json.user.name = \"Tom\";
json.user.tags = [];
json.user.tags[0] = \"a\";
json.user.tags[1] = \"b\";
");

// …and back again.
assert_eq!(gron::ungron(&lines).unwrap(), v);

Flat assignment lines are perfect for grep, diff, and sed over JSON.

Enums§

UngronError
An error produced while parsing gron lines in ungron.

Functions§

gron
Flatten value into gron assignment lines using the default root json.
gron_with_root
Flatten value into gron assignment lines using a custom root identifier.
ungron
Reconstruct a Value from gron assignment lines.