Skip to content

Releases

json 3.1.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 26 Oct 15:15
6f88547

Requires Mojo >= 1.2.0 (std.hashlib renamed std.hash). For Mojo 1.0/1.1 use json 3.0.2.

v3.0.1

Choose a tag to compare

@Mosaad-M Mosaad-M released this 03 Oct 15:16
9a02210

Fix: json 3.0.0 failed to compile on Linux together with code that declares clock_gettime with a different signature than Mojo's stdlib, e.g. requests 1.1 ("existing function with conflicting signature"). The per-object hash seed for built objects no longer reads a clock; it comes from a heap address instead, which ASLR randomizes per process. A regression test runs on Linux CI. No API changes. See CHANGELOG.md.

v3.0.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 03 Oct 15:02
21d8d12

Parsed documents now use a flat layout, as yyjson does: one contiguous block of 16-byte values plus a string arena. Parsing is up to 3.9× faster and uses up to 10× less memory, and the library no longer recurses anywhere. Breaking API change; read-only 2.x code compiles unchanged.

Highlights

  • parse_json returns a read-only JsonDoc. Lookups (doc["k"], doc[0]) return JsonRef views instead of deep copies. The compiler keeps the document alive while a view is in use.
  • New:
    • items() and entries() for iteration;
    • as_string_slice() for zero-copy strings;
    • to_value() for a mutable JsonValue copy.
  • Faster parsing than 2.0.0: mixed documents 3.9× faster (62.6 → 15.9 ms); integers and floats 1.1–1.3×. Serialization is on par or faster.
  • Less memory: parsing adds at most about 8× the input size in the worst case ([0,0,…]), down from 85×, and about 3× for typical documents.
  • No recursion anywhere: parsing, serialization, copy, conversion and destruction are all iterative, for parsed documents and built trees alike. A 1M-deep built tree works; 2.0 crashed at about 10k.
  • No hash flooding: parsed objects use a sorted key index; built objects hash keys with a random seed per object.

Migrating from 2.x

  • Mutating a parsed document: var v = parse_json(s).to_value(), then v.set(...) / v.append(...).
  • Keeping a value after its document is gone: use to_value(). The compiler rejects views that would outlive their document.
  • Functions that took a parsed JsonValue can take JsonRef[_] or JsonDoc instead.

See CHANGELOG.md for details and benchmarks.

v2.0.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 03 Oct 14:28
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.

v1.1.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 24 Sep 20:07

Migrate to Mojo 1.0.0 (stable). Removes the spurious AVX-512 CI check. 39/39 tests pass.

v1.0.1

Choose a tag to compare

@Mosaad-M Mosaad-M released this 22 Mar 16:05

Mojo 0.26.2 compatibility: fn→def migration, UnsafePointer[T, _] origin fix