Home / Docs / Specification / 29. Numerics

29.10 JSON

Release v0.4.0
  1. Parsing is unchanged. A JSON number with a fraction or an exponent stays Decimal(text) (spec/23 §1).
  2. as_f64(j) gives, for Number(n), Some(n.to_f64()); for Decimal(t), Some of parse_f64(t), which never fails on a JsonNumber; and None for every other Json. A number beyond the range gives Some of an infinity.
  3. json_number(x) gives Some(Decimal(t)) with t the rendering of §7 for a finite x, and None for NaN and the infinities. -0.0 gives Decimal("-0.0").
  4. Round trip. For every finite x, json_number(x), written by to_json, read by parse_json and converted by as_f64, gives Some(x), bit for bit.
  5. Labels. Both functions label their result with their argument's labels.