Mercurial > repos > ufz > dfpl_predict
diff json_flatten.py @ 0:8956e949d466 draft default tip
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/dfpl commit 66c6acfeff5441c36fba97787ddc5ee3d6a4a6ec
author | ufz |
---|---|
date | Thu, 19 Dec 2024 12:51:08 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/json_flatten.py Thu Dec 19 12:51:08 2024 +0000 @@ -0,0 +1,21 @@ +import json +from sys import stdin + +d = json.load(stdin) + + +def flatten(o: dict): + d_flat = {} + for key, value in o.items(): + if type(value) is dict: + value = flatten(value) + for k, v in value.items(): + d_flat[k] = v + else: + d_flat[key] = value + return d_flat + + +d = flatten(d) + +print(json.dumps(d))