Skip to content

JSON Conformance

Lanexio™ Parser supports three JSON-family grammars through a single package: strict JSON (RFC 8259), JSONC (JSON with comments), and JSON5 (ECMAScript 5 relaxations). All three share the same never-throw parse path and zero-copy flat AST.

Strict JSON mode (parseJson) conforms to RFC 8259. String escaping, number parsing, whitespace handling, and duplicate-key behavior follow the spec.

The parser is validated against the JSONTestSuite, the reference conformance corpus for JSON parsers:

CategoryResult
y_* (must accept)All pass — never-throw, root is not Error
n_* (must reject)All pass — parse succeeds but root is Error
i_* (implementation-defined)All pass — never-throw, caller decides semantics

The JSON grammar is never-throw: malformed input produces a tree with an Error root node rather than throwing an exception. Callers inspect tree.root.hasError to determine parse success.

  • JSONC strips line (//) and block (/* */) comments before parsing.
  • JSON5 relaxes JSON syntax: trailing commas, unquoted keys, single-quoted strings, hexadecimal numbers, and Infinity/NaN literals.

Both modes use the same parse path as strict JSON and carry the same never-throw and well-formed guarantees.

AxisResult
never-throw0 throws across 14,185 corpus files
well-formedcorpus WF = 0
losslesscorpus lossless = 0 (BOM fixed)
conformanceJSONTestSuite: all y_, n_, i_* categories pass

pnpm conformance:suite measured this family over the test_files/json corpus on 2026-10-06 at Lanexio™ Parser version 1.0.0:

familyvalidinvalidrawcontract-subsetREAL-DEFECT
json1895123398.4%100.0% (18646/18646)0

The contract-subset is artifact-adjusted: 305 valid-classified files report an error, and each is accounted for by one of three documented buckets, so none is silently dropped and the REAL-DEFECT count is 0. Every bucketed file still reports an error node, so acceptance behavior is unchanged.

BucketFilesRule
json5-generated-malformed-numeric294Path under test_files/json5/generated/, basename doc_*.json5, and a numeric token with a second decimal point (/\.\d+\.\d+/).
lone-surrogate-escape-policy10A \uD800-\uDFFF escape that is not the lead or trail half of a valid surrogate pair (RFC 8259 section 8.2 permits the ABNF; corpus/json/i_policy.md emits an error node).
mislabeled-valid-fixture-unbalanced1Path under test_files/json/edge-cases/ with unequal brace counts.

The raw figure counts both directions over every classified file; the 1 invalid-classified input that is not flagged is included in the raw denominator.