Registry / serialization / gron
library1.4.0pypypi✓ verified 84d ago

`gron` is a Python library and command-line tool that transforms JSON into a more "greppable" format, where each field is represented as a distinct, path-based line, making it easier to search and manipulate. It also provides functionality to convert the "gron" format back to JSON. The current version is 1.4.0, and it sees active development with minor feature releases.

pip install gron
INSTALL
IMPORT
SIG · GRON
G
gron
serializationpythonv1.4.0
Install
1.6s avg
Import
14ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gron
import gron
The main library module is named 'gron'.
json_to_gron
from gron import json_to_gron
For direct access to the JSON to gron conversion function.
gron_to_json
from gron import gron_to_json
For direct access to the gron to JSON conversion function.

This quickstart demonstrates how to convert a Python dictionary (serialized to JSON) into the `gron` format, and then how to convert a `gron` formatted string back into a Python dictionary, showcasing the core library functions.

import gron import json data = {'name': 'Alice', 'age': 30, 'address': {'street': '123 Main St', 'city': 'Anytown'}} json_string = json.dumps(data, indent=2) # Convert JSON to gron format gron_output = gron.json_to_gron(json_string) print("--- Gron Output ---") print(gron_output) # Example gron string (usually from json_to_gron output) gron_lines = """ json = {}; json.name = "Alice"; json.age = 30; json.address = {}; json.address.street = "123 Main St"; json.address.city = "Anytown"; """ # Convert gron format back to JSON json_back = gron.gron_to_json(gron_lines) print("\n--- JSON Back ---") print(json.dumps(json_back, indent=2))
gron --version
Debug
Known issues
gotchaThe `gron_to_json` function expects input strictly adhering to the `gron` format (e.g., `json.key = "value";`). Malformed gron strings or non-gron input will result in parsing errors.
fix
Ensure the input string for `gron_to_json` is valid `gron` output or manually constructed using the correct syntax. Pay attention to semicolons, `json = {};` initialization, and proper pathing.
affects: All versions
gotchaThe `gron` format flattens nested JSON objects and arrays into individual, path-based lines. Users expecting a re-structured but still hierarchical JSON output from `json_to_gron` will find the output is primarily for line-by-line processing.
fix
Understand that `gron`'s purpose is flattening JSON for greppability. To revert to a hierarchical JSON structure, you must use `gron_to_json` on the `gron` output.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'gron' has no attribute 'json_to_gron'
The `gron` library was installed but the functions are not being accessed correctly, or an older version without these functions might be installed, or another module is shadowing the `gron` name.
fix
Ensure `pip install gron` is successful and you are importing the `gron` module, then accessing its functions via `gron.json_to_gron()` and `gron.gron_to_json()`. Verify the installed version with `pip show gron`.
gron.exceptions.GronParsingError: Unable to parse gron input at line X (e.g., at 'unexpected token Y')
The input string provided to `gron.gron_to_json()` does not conform to the expected `gron` syntax.
fix
Review the `gron` input string for syntax errors, such as missing semicolons, incorrect value assignments, unquoted strings that should be quoted, or invalid path definitions. The `gron` format is strict.
Upgrade
Version history
1.4.0latest on PyPI · released Aug 24, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources
gron — pip install gron · libregistry