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
treecommand, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49e0633d8d747a5936fb2ce4421f4855c98a0d1437fc581295158c558b4d7cbc
|
|
| MD5 |
dfca229c472878598bf35f184bc56a42
|
|
| BLAKE2b-256 |
7118ce12eed6227a58595f534d106e087d5e2892c3c0a5eca56239f75b2f2338
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27e2e228b74886f30ee8255fd01ed907f76d7da8adb5fc92008f9cd502051428
|
|
| MD5 |
62ea61630512b2928327a14bd44c4dd1
|
|
| BLAKE2b-256 |
1106449663b614c19722a75d08fff298a90a574788c6025fe980c2e4c3a83601
|