On this page

0085. JSON null decodes to the outer option none

Context

ADR-0083 represents option none as JSON null and newtypes as their representation. For option<option>, none and some(none) therefore have identical encodings. An outer option around a newtype whose representation is optional has the same ambiguity. The Step 6.3 golden tests/programs/codec-json-encode-shapes already pins option<option> encoding for none, some(none) and some(some(7)). We accept the loss of the some(none) distinction to preserve those accepted shapes and the existing null-based wire rule: some(some(x)) round-trips, while only some(none) normalizes to none.

Decision

Decode null as the outer option's none, including through transparent newtypes. Keep the existing encoder output, which deliberately includes nested options in the Step 6.3 codec-json-encode-shapes golden. Non-null input decodes recursively as some(payload). Document that some(none) normalizes to none; an explicit enum is needed when the distinction matters. No compiler or existing golden output changes are needed.

Alternatives considered

Consequences

Required keys and null-as-none remain consistent at every nesting level. Nested options are not injective on the JSON wire, as already true of their encoders; tests pin the normalization. A future alternative representation needs a new decision; binary option tags are unaffected.