I have a JSON file and need to update with new key value pair.
cuurent json:
[{'Name': 'AMAZON',
'Type': 'Web',
'eventTimeEpoch': 1611667194}]
I need to add a location parameter and update it as "USA"
.But when try to update it with below code it append to location parameter with value to end. Like below.
[{'Name': 'AMAZON',
'Type': 'Web',
'eventTimeEpoch': 1611667194,
'location': 'USA'}]
How can I add this location
parameter after the Name
.
Expected output:
[{'Name': 'AMAZON',
'location': 'USA',
'Type': 'Web',
'eventTimeEpoch': 1611667194
}]
Current code:
filename='test.json'
jsonFile = open(filename, "r") # Open the JSON file for reading
data = json.load(jsonFile)
jsonFile.close()
data[0]["location"] = "USA"
data