Skip to main content

Pretty JSON/tree viewer using Rich in the terminal

Project description

rich-json-tree

๐Ÿชต Pretty-print JSON and nested Python structures as a colorful Rich-powered tree โ€” like the tree command, but for data.

rich-json-tree helps you quickly explore deeply nested JSON, config files, API responses, schemas, or any Python dictionary/list structure โ€” with clear formatting, icons, type hints, and size information.

If you've ever printed a messy 300-line dict and squinted at indentation trying to understand it โ€” this tool is for you.


โœจ Features

  • ๐ŸŽจ Beautiful text-tree visualization using Rich

  • ๐Ÿ”ค Detects types automatically (dict, list, str, int, None, etc.)

  • ๐Ÿ“ Shows collection sizes (keys/items)

  • ๐Ÿ’ก Configurable:

    • Max depth
    • Max list items displayed
    • Value preview length
    • Optional key sorting
  • ๐Ÿ›‘ Cycle detection (avoids infinite loops)

  • ๐Ÿงช Works with standard Python objects โ€” no JSON required


๐Ÿ“ฆ Installation

pip install rich-json-tree

๐Ÿš€ Usage Example

from rich_json_tree import print_json_tree

data = {
    "user": {
        "name": "Alice",
        "age": 30,
        "skills": ["Python", "SQL"],
        "active": True
    },
    "meta": {"source": "api", "timestamp": "2025-01-08"}
}

print_json_tree(data, name="payload")

Output (example)

๐Ÿ“ payload  (dict, 2 keys)
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ user  (dict, 4 keys)
โ”‚   โ”œโ”€โ”€ ๐Ÿ”ค name = 'Alice'  (str)
โ”‚   โ”œโ”€โ”€ ๐Ÿ”ข age = 30  (int)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“š skills  (list, 2 items)
โ”‚   โ”‚   โ”œโ”€โ”€ [0] = 'Python'  (str)
โ”‚   โ”‚   โ””โ”€โ”€ [1] = 'SQL'  (str)
โ”‚   โ””โ”€โ”€ โœ… active = True  (bool)
โ”‚
โ””โ”€โ”€ ๐Ÿ“ meta  (dict, 2 keys)
    โ”œโ”€โ”€ ๐Ÿ”ค source = 'api'  (str)
    โ””โ”€โ”€ ๐Ÿ”ค timestamp = '2025-01-08'  (str)

โš™๏ธ Configuration Options

Customize behavior by passing keyword arguments:

print_json_tree(
    data,
    name="response",
    max_items=3,      # show only first 3 list items
    max_depth=4,     # stop at depth level 4
    max_string=80,   # show up to 80 characters for values
    sort_keys=True,  # sort dict keys alphabetically
)

๐Ÿงฉ API Reference

print_json_tree(data, name="root", **options)

Option Type Default Description
max_items int 5 Max list elements to print
max_depth int or None None Limits recursion depth
max_string int 40 Max characters for string previews
sort_keys bool True Sort dictionary keys
show_types bool True Display type info on leaves
show_lengths bool True Display list size / dict keys count

๐Ÿ“ CLI Support (optional future feature)

A CLI command may be added in future releases:

rich-json-tree data.json

๐Ÿ”ง Environment Compatibility

  • Python 3.8+

  • OS: Windows, macOS, Linux

  • Works in:

    • VSCode terminal
    • PyCharm
    • Jupyter
    • Standard terminals

๐Ÿชช License

MIT โ€” free to use, modify, and contribute.


๐Ÿค Contributing

Pull requests, ideas, and feature requests are welcome!

git clone https://github.com/<yourname>/rich-json-tree
cd rich-json-tree

โญ If you find this helpful...

Please consider starring the repository โ€” it helps others discover the tool ๐ŸŒŸ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_json_tree-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_json_tree-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file rich_json_tree-0.1.0.tar.gz.

File metadata

  • Download URL: rich_json_tree-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for rich_json_tree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49e0633d8d747a5936fb2ce4421f4855c98a0d1437fc581295158c558b4d7cbc
MD5 dfca229c472878598bf35f184bc56a42
BLAKE2b-256 7118ce12eed6227a58595f534d106e087d5e2892c3c0a5eca56239f75b2f2338

See more details on using hashes here.

File details

Details for the file rich_json_tree-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rich_json_tree-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for rich_json_tree-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27e2e228b74886f30ee8255fd01ed907f76d7da8adb5fc92008f9cd502051428
MD5 62ea61630512b2928327a14bd44c4dd1
BLAKE2b-256 1106449663b614c19722a75d08fff298a90a574788c6025fe980c2e4c3a83601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page