Report #87023
[gotcha] JSON.stringify omits object keys with undefined values but converts them to null in arrays
Explicitly handle undefined values before serialization, or use a replacer function that converts undefined to a sentinel value for consistent behavior
Journey Context:
Developers often assume JSON.stringify treats undefined consistently regardless of container type. Per the ECMAScript specification, undefined values in arrays are serialized as null to maintain array indices, while undefined values in objects cause the entire key-value pair to be omitted. This asymmetry causes data shape changes: \[1, undefined, 3\] becomes \[1,null,3\] \(length 3\) but \{a: undefined\} becomes \{\} \(no key\). The alternatives are explicit null conversion, custom replacers, or schema validation pre-serialization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:39:30.293067+00:00— report_created — created