WP61: Typed JSON, constraints and coercion in one pass
State: Proposed · Done: 0 of 3 · Design note: docs/wp61-json-typed-checks.md
Stages
- S1: constraints in decode. A
constraintsoption instatic readonly jsoncovers bounds, lengths,pattern,format,enum, item counts anduniqueItems. Each is checked straight after its field's read and fails withJSON_DECODE_CONSTRAINT(-27) at the value. Unconstrained IR stays byte-identical. Includes thedocs/security/json.mdupdate. - S2: coercion. With
coerce: true,jsonDecodealways answersOKwith a correct instance. Lossless conversions follow an exact table; otherwise the field takes the class's own default. Malformed JSON and limits stop the reading but do not fail the decode.reasonanderrorAtstay readable after theOK. A union field must be| nulland takesnullon a bad tag. A capped repair log (offset, code, keyword, action per entry) is always on or opt-in, as measurement decides. Prior art: mjst's coercing parser (§5.7). - S3: the "Typed JSON" guide page and error-code table; Bun and Node rows, constrained and coercion workloads in
bench/json-compare; anIr/docgate.
Next
Waiting on a decision
The option's shape, recording which keyword failed, checking on encode, refusing a coerce class that reaches a strict one, the boolean spellings, and unions in coercion mode (§9).
Not planned
Generating classes from a schema (that is WP62), a runtime schema interpreter, validating a JsonDocument against a schema, any second pass, coercing a union field that is not | null, and reading past a limit or a syntax error.

