Repository navigation
Releases
json 3.1.0
v3.0.1
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
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_jsonreturns a read-onlyJsonDoc. Lookups (doc["k"],doc[0]) returnJsonRefviews instead of deep copies. The compiler keeps the document alive while a view is in use.- New:
items()andentries()for iteration;as_string_slice()for zero-copy strings;to_value()for a mutableJsonValuecopy.
- 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(), thenv.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
JsonValuecan takeJsonRef[_]orJsonDocinstead.
See CHANGELOG.md for details and benchmarks.
v2.0.0
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
reprstyle, byte-identical to Python'srepr, and parse back to the same value bit for bit. - Full Unicode.
\uXXXXescapes, 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.
- A nesting limit (
- 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, not100), and exponents look like1e+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.