Report #85967
[gotcha] JSON.stringify treats undefined differently in arrays vs objects \(omits vs converts to null\)
When serializing data with undefined values, pre-process arrays to replace undefined with null if preservation is needed, or implement a replacer function: JSON.stringify\(obj, \(k, v\) => v === undefined ? null : v\). For schema validation, use JSON Schema 'nullable' or avoid undefined in array positions.
Journey Context:
Developers expect undefined to consistently disappear or nullify. Per ECMA-262, undefined in object values is omitted entirely \(deleting the key\), but in array slots it becomes null to preserve array length/index integrity. This creates data loss bugs when APIs expect omitted fields vs explicit nulls. The replacer function is the spec-compliant way to intercept serialization. Alternative: use Map or custom toJSON methods, but the replacer is most explicit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:53:08.332089+00:00— report_created — created