#json #nan #infinity #python #serde-json #deserialize-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

#2575 in Parser implementations

Download history 525/week @ 2024-03-13 566/week @ 2024-03-20 457/week @ 2024-03-27 236/week @ 2024-04-03 279/week @ 2024-04-10 339/week @ 2024-04-17 430/week @ 2024-04-24 179/week @ 2024-05-01 400/week @ 2024-05-08 361/week @ 2024-05-15 511/week @ 2024-05-22 358/week @ 2024-05-29 250/week @ 2024-06-05 280/week @ 2024-06-12 406/week @ 2024-06-19 217/week @ 2024-06-26

1,232 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–270KB