Files
slic/json_to_tree.py
tligui_y ada55c28f8
Run Pytest with HTML and XML Test Reports / tests (push) Successful in 24s
Update json_to_tree.py
2025-07-16 13:42:08 +02:00

44 lines
1.2 KiB
Python

from io import StringIO
from rich.console import Console
from rich.tree import Tree
import json
import sys
import os
def build_tree(data, tree):
if isinstance(data, dict):
for key, value in data.items():
if isinstance(value, (dict, list)):
branch = tree.add(f"{key}")
build_tree(value, branch)
else:
tree.add(f"{key}: {value}")
elif isinstance(data, list):
for value in data:
if isinstance(value, (dict, list)):
branch = tree.add("-")
build_tree(value, branch)
else:
tree.add(f"{value}")
def main():
file_path = sys.argv[1]
with open(file_path, 'r') as f:
data = json.load(f)
os.makedirs("ci-reports/markdown", exist_ok=True)
buffer = StringIO()
console = Console(file=buffer, record=True, force_terminal=True, color_system="truecolor")
root = Tree(f"📁 {file_path}")
build_tree(data, root)
console.print(root)
with open("ci-reports/markdown/json-tree-view.txt", "w") as f:
f.write(console.export_text(clear=False))
if __name__ == "__main__":
main()