The comment are causing errors. I have a contents.json
file which looks like:
{
"Fridge": [
["apples"],
["chips","cake","10"] // This comment here is causing error
],
"car": [
["engine","tires","fuel"],
]
}
My python script is like this
import json
jsonfile = open('contents.json','r')
jsondata = jsonfile.read()
objec = json.loads(jsondata)
list_o = objec['Fridge']
for i in (list_o):
print(i)
In my list_o
, i am trying to load Fridge
from contents.json
file, when JSON file has that comment, it gives me an error, when the JSON file doesn't have the comment, the script runs properly.
I understand that comments is not proper JSON format, but is there any way to ignore comments of JSON file?