{
"names": [
{
"firstname": "Jim",
"age": 32
},
{
"firstname": "Test",
"age": 32
}
{
"firstname": "Bob",
"age": "28"
}
]
}
Above is my current JSON script. I’m trying to update my current JSON script with this code below:
import json
def write_json(data, filename="05_new_json_script.json"):
with open (filename, "w") as f:
json.dump(data, f, indent=4)
with open ("05_new_json_script.json") as json_file:
data = json.load(json_file)
temp = data["names"]
y = {"firstname": "Joe", "age": 40}
temp.append(y)
write_json(data)
However, I have received the error:
Exception has occurred: JSONDecodeError
Expecting ',' delimiter: line 12 column 9 (char 176)
File "C:UsersUserOneDrive - Innergia Labs Sdn BhdPython Practicesample.py", line 8, in <module>
data = json.load(json_file)
^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 12 column 9 (char 176)
The intended result for the code is to have added script of:
{
"firstname": "Joe",
"age": "40"
}
2
Answers
The problem is that you’re missing a ",".
here you need , at the end of the object like:
The Json is broken at row number 10. adding a comma will be solving the problem for you.