This commit is contained in:
i 2026-02-07 13:50:59 +01:00
parent 4f4046e4a0
commit 716a565713
6 changed files with 1471 additions and 15 deletions

View file

@ -1,8 +1,24 @@
import json
with open("nice.json", "r", encoding="utf-8") as f:
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
keys_to_keep = {"name"}
keys_to_keep2 = {"attributes", "id"}
for i in data["data"]:
print("%-32s id: %s" % (i["attributes"]["name"], i["id"]))
print(type(data)) # usually <class 'dict'>
attr = i["attributes"]
for key in list(attr.keys()):
if key not in keys_to_keep:
del attr[key]
for key in list(i.keys()):
if key not in keys_to_keep2:
del i[key]
# i["attributes"].pop("description", None) # safe remove
# i["attributes"].pop("plain_description", None) # safe remove
with open("data.json", "w") as f:
json.dump(data, f, indent=2)
# for i in data["data"]:
# print("%-32s id: %s" % (i["attributes"]["name"], i["id"]))
# print(type(data)) # usually <class 'dict'>