diff --git a/json_to_tree.py b/json_to_tree.py index 5b73eb1..2251c8d 100644 --- a/json_to_tree.py +++ b/json_to_tree.py @@ -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]