|
1 | 1 | # orjson |
2 | 2 |
|
3 | 3 | orjson is a fast, correct JSON library for Python. It benchmarks as the |
4 | | -fastest Python library for JSON and has comprehensive unit, integration, and |
5 | | -interoperability tests. |
| 4 | +fastest Python library for JSON and is more correct than the standard json |
| 5 | +library or third-party libraries. |
6 | 6 |
|
7 | 7 | Its serialization performance is 2.5x to 9.5x the nearest |
8 | 8 | other library and 4x to 12x the standard library. Its deserialization |
@@ -232,15 +232,32 @@ JSONEncodeError: Integer exceeds 53-bit range |
232 | 232 |
|
233 | 233 | ### float |
234 | 234 |
|
235 | | -orjson serializes and deserializes float values in a consistent way. The |
236 | | -same behavior is observed in rapidjson, simplejson, and json. ujson is |
237 | | -inaccurate in both serialization and deserialization. |
| 235 | +orjson serializes and deserializes floats with no loss of precision and |
| 236 | +consistent rounding. The same behavior is observed in rapidjson, simplejson, |
| 237 | +and json. ujson is inaccurate in both serialization and deserialization, |
| 238 | +i.e., it modifies the data. |
| 239 | + |
| 240 | +`orjson.dumps()` serializes Nan, Infinity, and -Infinity, which are not |
| 241 | +compliant JSON, as `null`: |
| 242 | + |
| 243 | +```python |
| 244 | +>>> import orjson |
| 245 | +>>> orjson.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) |
| 246 | +b'[null,null,null]' |
| 247 | +>>> ujson.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) |
| 248 | +OverflowError: Invalid Inf value when encoding double |
| 249 | +>>> rapidjson.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) |
| 250 | +'[NaN,Infinity,-Infinity]' |
| 251 | +>>> json.dumps([float("NaN"), float("Infinity"), float("-Infinity")]) |
| 252 | +'[NaN, Infinity, -Infinity]' |
| 253 | +``` |
238 | 254 |
|
239 | 255 | ### UTF-8 |
240 | 256 |
|
241 | 257 | orjson raises an exception on invalid UTF-8. This is |
242 | | -necessary because Python 3 str objects may contain UTF-16 surrogates. The |
243 | | -standard library's json module accepts invalid UTF-8. |
| 258 | +necessary because Python 3 `str` objects may contain UTF-16 surrogates. |
| 259 | + |
| 260 | +The standard library's json module deserializes and serializes invalid UTF-8. |
244 | 261 |
|
245 | 262 | ```python |
246 | 263 | >>> import orjson, ujson, rapidjson, json |
|
0 commit comments