Report #90526
[gotcha] JSON.stringify converts undefined array elements to null but strips undefined object properties entirely
Explicitly filter or map undefined values to null before serialization if preserving array length is critical, or use a replacer function to handle undefined consistently across data structures; validate deserialized arrays for null placeholders
Journey Context:
ECMAScript's JSON.stringify specification treats undefined differently depending on container type. In objects, undefined values are completely omitted \(deleting the key\), while in arrays, undefined is stringified as null to preserve the array length and index alignment. This asymmetry corrupts data schemas like \[string, number \| undefined\] tuples where undefined carries semantic meaning \(optional second element\), as it becomes indistinguishable from null upon deserialization. Developers often assume undefined serializes consistently or is universally stripped, leading to type mismatches in APIs that consume the JSON.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:32:25.633563+00:00— report_created — created