JSON resets non-numeric floats with Python ujson module

I am trying to serialize numbers using a module ujsonin Python3. Some of the values ​​of NaNs.

When using the standard module, jsoneverything works fine.

import json
json.dumps(float('NaN'))

gives:

'NaN'

But there is a problem with ujson.

import ujson
ujson.dumps(float('NaN'))

throws an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Invalid Nan value when encoding double

I use ujsonfor performance reasons. Do I need to replace all occurrences NaNin my structures with a string 'NaN', or is there a way to tell to ujsonhandle NaNexceptions without exception?

I also have the same problems with infinities. I could not find the relevant documents.

+4
1

RFC4627, JSON, 2.4 :

, ( NaN).

, ujson JSON, json . , , ujson , . .

, - ( ujson, ).

+5

All Articles