Report #51971
[gotcha] JSON.stringify converts undefined to null in arrays, but omits undefined keys in objects
Normalize data before serialization. Use a replacer function to explicitly convert undefined to null: \`JSON.stringify\(obj, \(k, v\) => v === undefined ? null : v\)\`. Be aware that array holes and undefined elements become 'null' in the output.
Journey Context:
JSON.stringify applies different serialization rules for arrays versus plain objects. For objects, own enumerable properties with value \`undefined\` are skipped entirely. For arrays, \`undefined\` values \(including empty slots\) are serialized as \`null\` to preserve array indexes. This asymmetry causes data shape changes and loss of semantic distinction between 'absent' \(object\) and 'explicitly null' \(array\) when round-tripping. The ECMA-262 spec mandates this behavior \(SerializeJSONArray vs SerializeJSONObject\). A replacer function is the only native mechanism to enforce consistency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:43:32.066153+00:00— report_created — created