rust-embedded-community / serde-json-core

`serde-json` for `no_std` programs
Apache License 2.0
161 stars 59 forks source link

float inf nan #64

Closed jordens closed 2 years ago

jordens commented 2 years ago

Currently f{32,64}::NAN, INFINITE and NEG_INFINITY (i.e. if !v.is_finite()) are all emitted like their ryu serializations. This is wrong and breaks JSON. Instead, emit null, like serde_json does. On deserialization, interpret null as NAN where f32 or f64 is expected. This isn't exactly what serde_json does (it errors out instead), but makes the round-trip closer and somewhat more robust. And many would claim that it is common to interpret a JSON null as NAN where a float is expected (from schema/context/protocol).