Page 1 of 1

Q.on use of ujson

Posted: Mon Nov 29, 2021 10:53 pm
by ebolisa
Hi,

The following code fails on an ESP because the data file contains a string. However, it runs on my win box.
Why is that?
TIA

Code: Select all

#alarm = [1, 2, 3, '4']
import ujson
data_file = 'data.json'
alarm = []
# with open(data_file, 'w') as f:
#     ujson.dump(alarm, f)
with open(data_file, 'r') as f:
    alarm = ujson.load(f)
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 11, in <module>
ValueError: syntax error in JSON

Re: Q.on use of ujson

Posted: Mon Nov 29, 2021 11:29 pm
by curt
Are you sure the read is actually reading the entire file?

Re: Q.on use of ujson

Posted: Tue Nov 30, 2021 7:13 am
by stijn
Just a guess but have you tried with 'rb' instead of 'r'? Also: hard to tell without seeing the exact file contents.

Re: Q on use of ujson

Posted: Tue Nov 30, 2021 7:31 am
by ebolisa
Sorry for the late reply. It was bed time for me right after I posted the question.

The json syntax error drove me nuts till I found out it was the text datatype in the array the the culprit.

However, it's working this morning, so I can only guess the ESP needed to be cooled down :|