Python Gron

1.4.0 · active · verified Fri Apr 17

`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.

Common errors

Warnings

Install

Imports

Quickstart

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))

view raw JSON →