#nan #python #json

python-json-read-adapter

A crate that adds a read adapter to deal with bad Python caused JSON payloads (NaNs and Infinities)

1 unstable release

0.1.0 Dec 19, 2018

#14 in #nan

Download history 285/week @ 2024-07-25 290/week @ 2024-08-01 397/week @ 2024-08-08 315/week @ 2024-08-15 228/week @ 2024-08-22 311/week @ 2024-08-29 324/week @ 2024-09-05 138/week @ 2024-09-12 232/week @ 2024-09-19 302/week @ 2024-09-26 119/week @ 2024-10-03 387/week @ 2024-10-10 400/week @ 2024-10-17 306/week @ 2024-10-24 252/week @ 2024-10-31 319/week @ 2024-11-07

1,366 downloads per month

BSD-3-Clause

9KB
134 lines

python-json-read-adapter

This crate implements a Read adapter that converts the invalid JSON tokens NaN and Infinity into other tokens without otherwise distorting the stream. It achieves this by converting NaN and Infinity into 0.0.

This is useful because the Python JSON library traditionally emits invalid JSON if NaN and Infinity values are encountered. If you have to support clients like this, this wrapper can be used to still deserialize such a JSON document.

This is just a way to get this to parse and 0.0 is the only value that can be inserted in a standardized way that fits without changing any of the positions.


lib.rs:

This crate implements a Read adapter that converts the invalid JSON tokens NaN and Infinity into other tokens without otherwise distorting the stream. It achieves this by converting NaN and Infinity into 0.0.

This is useful because the Python JSON library traditionally emits invalid JSON if NaN and Infinity values are encountered. If you have to support clients like this, this wrapper can be used to still deserialize such a JSON document.

This is just a way to get this to parse and 0.0 is the only value that can be inserted in a standardized way that fits without changing any of the positions.

Example Conversion

The following JSON document:

{"nan":NaN,"inf":Infinity,"-inf":-Infinity}

is thus converted to:

{"nan":0.0,"inf":0.0     ,"-inf":-0.0     }

serde support

If the serde feature is enabled then the crate provides some basic wrappers around serde_json to deserialize quickly and also by running the conversions.

Dependencies

~0–290KB