summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/utils.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/cli/utils.py b/cli/utils.py
index 49fbddb..56fe723 100644
--- a/cli/utils.py
+++ b/cli/utils.py
@@ -29,10 +29,27 @@ def ips_in_scope(scope):
ips += ips_in_scope(child)
return ips
+def reorder_json_tree(payload):
+ if isinstance(payload, list):
+ elements = payload[:]
+ for val in elements:
+ if isinstance(val, (dict, list)):
+ payload.remove(val)
+ payload.append(val)
+ reorder_json_tree(val)
+ elif isinstance(payload, dict):
+ keys = list(payload.keys())
+ for k in keys:
+ val = payload[k]
+ if isinstance(val, (dict, list)):
+ del payload[k]
+ payload[k] = val
+ reorder_json_tree(val)
def print_json(text):
payload = json.loads(text)
- print(json.dumps(payload, sort_keys=True, indent=2))
+ reorder_json_tree(payload)
+ print(json.dumps(payload, indent=2))
def check_address(addr):
try: