Skip to content

v2.0.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 03 Oct 14:28
· 11 commits to master since this release
4df0d10

Correctness, security and performance overhaul. Parsing is now strict RFC 8259, and every number is converted exactly. Contains breaking changes; see below.

Highlights

  • Strict RFC 8259 parsing. Passes every applicable accept/reject case of JSONTestSuite.
  • Exact numbers.
    • Int64 integers are stored exactly; they used to overflow silently past 18 digits.
    • Floats are correctly rounded (Eisel-Lemire plus an exact fallback). The parser no longer uses Mojo's stdlib atof, which isn't correctly rounded.
  • Exact float output. Floats print with Schubfach in CPython repr style, byte-identical to Python's repr, and parse back to the same value bit for bit.
  • Full Unicode. \uXXXX escapes, including surrogate pairs, decode to UTF-8.
  • Hardened for untrusted input.
    • A nesting limit (max_depth=512) replaces a stack-overflow crash.
    • Large objects use a hash index: a 100k-key object went from 18 s to 3 ms.
    • Memory use is bounded better.
    • Error messages are safe to log.
  • New API: append(), set(), json_int(), is_int().
  • Serialization is 2–5× faster.

Breaking changes

  • Input that RFC 8259 forbids now raises: 01, 1., \x, raw control characters, lone surrogates, 1e400.
  • Integral floats keep their .0 (100.0, not 100), and exponents look like 1e+16 / 1e-05. Integers are unchanged.
  • len() of a string value counts codepoints, not bytes.
  • as_int() / get_int() raise for floats outside Int64 range.

Upgrading

json.mojo is still a single self-contained file: replace your copy, or update the submodule, and rebuild. Requires Mojo ≥ 1.0.0.

See CHANGELOG.md for the full list, benchmarks and known limitations. 71 tests, conformance and differential fuzzing run in CI on Linux and macOS.