when I try to run this code I am experiencing an error.
import ujson as json
input = '{"a":NaN}'
print(json.loads(input))
Error
print(json.loads(input))
ValueError: Expected object or value
I gone through some blogs and realized that ujson won't handle nan
or NaN
values while performing json.loads
operation.
My final goal: I want to
- use ujson to load the string into JSON-FORMAT
- handle this type of VALUE ERRORS
- load the input string into JSON
Note:my input might be nested json structure
input = {"name":"siva","details":{"id":"111","qualification":nan},"marks":[{"grade1":90,"grade2":null,"grade3":NaN}]}
Expected output
{"a":NaN}
{"name":"siva","details":{"id":"111","qualification":nan},"marks":[{"grade1":90,"grade2":null,"grade3":NaN}]}
Can anyone suggest a solution for this?
I'm not sure what is the expected output that you seek (it will be great if you could also add it).
The following code will perform without any errors: