I want to update a key name in my json file, the objects in the file look like:
[{"marka": "تويوتا" , "tag" : "MANF"},
{"marka": "شيفروليه" , "tag" : "MANF"},
{"marka": "نيسان" , "tag" : "MANF"}]
I want to change the key name "marka" into "entity", so it will be something like this:
[{"entity": "تويوتا" , "tag" : "MANF"},
{"entity": "شيفروليه" , "tag" : "MANF"},
{"entity": "نيسان" , "tag" : "MANF"}]
This is the code I've tried but it gives an error:
import json
with open("haraj_marka_arabic.json", "r") as jsonFile:
data = json.load(jsonFile)
for d in data:
d["entity"] = d.pop("marka")
with open("haraj_marka_arabic.json", "w") as jsonFile:
json.dump(data, jsonFile)
The error is:
File "marka.py", line 8, in d["entity"] = d.pop("marka") KeyError: 'marka'