shreyas shreyas - 2 years ago 187
JSON Question

sending NaN in json

I am trying to encode an array which contains floats and

into JSON string from Python using

But the encoded JSON string is not being decoded successfully in PHP. Is the
causing this problem? How can I work around this situation?

Answer Source

json.dumps has an allow_nan parameter, which defaults to True.

NaN, Infinity and -Infinity are not part of JSON, but they are standard in Javascript, so they're commonly used extensions. If the recipient can't handle them, set allow_nan=False. But then you'll get ValueError when you try to serialise NaN.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download