import json 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"]: 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