Files
slic/json_to_tree.py
T
tligui_y d90a7c1f1e
Run Pytest with HTML and XML Test Reports / tests (push) Has been cancelled
Add json_to_tree.py
2025-07-16 13:12:14 +02:00

32 lines
813 B
Python

from rich.console import Console
from rich.tree import Tree
import json
import sys
def build_tree(data, tree):
if isinstance(data, dict):
for key, value in data.items():
branch = tree.add(f"[bold]{key}[/]")
build_tree(value, branch)
elif isinstance(data, list):
for i, item in enumerate(data):
branch = tree.add(f"[green]Item {i}[/]")
build_tree(item, branch)
else:
tree.add(f"[cyan]{data}[/]")
def main():
file_path = sys.argv[1]
with open(file_path, 'r') as f:
data = json.load(f)
console = Console(record=True)
root = Tree(f"📁 {file_path}")
build_tree(data, root)
console.print(root)
console.save_text("ci-reports/markdown/json-tree-view.txt")
if __name__ == "__main__":
main()