ValueError: syntax error in JSON
Posted: Sat Apr 10, 2021 10:54 pm
I'm trying to read/write a dict{} containing settings. I've read the docs, but I'm getting ValueError: syntax error in JSON when I try to read the settings. I'm not sure how to confirm they were written correctly. What am I missing? (sorry don't know why formatting is off, using CODE tags). There's some magic in between get/save to update the values saved in the dict{}.
I get this error:
Code: Select all
import ujson
import uos
import machine
class settings():
value={
'aaa' : "1",
'bbb' : "2",
'ccc' : "3",
'ddd' : "4",
'eee' : "5",
'fff' : "6",
'ggg' : "7",
'hhh' : "8",
'iii' : "9"
}
def get_cfg():
if 'config.json' in uos.listdir():
with open('config.json', 'rb') as f:
conf = ujson.load(f)
def save():
if 'config.json' in uos.listdir():
uos.rename('config.json', 'config.bak')
with open('config.json', 'wb') as f:
ujson.dump(conf, f)
conf = settings()
save()
get_cfg()
Code: Select all
File "main.py", line 38, in get_cfg
ValueError: syntax error in JSON