Update json_to_tree.py
This commit is contained in:
+5
-3
@@ -9,17 +9,19 @@ 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}")
|
||||
branch = tree.add(f"[bold]{key}[/bold]")
|
||||
build_tree(value, branch)
|
||||
else:
|
||||
tree.add(f"{key}: {value}")
|
||||
safe_value = str(value).replace("[", "\\[").replace("]", "\\]")
|
||||
tree.add(f"{key}: {safe_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}")
|
||||
safe_value = str(value).replace("[", "\\[").replace("]", "\\]")
|
||||
tree.add(f"{safe_value}")
|
||||
|
||||
def main():
|
||||
file_path = sys.argv[1]
|
||||
|
||||
Reference in New Issue
Block a user