Report #52289
[gotcha] JSON.stringify removes undefined in objects but converts to null in arrays
For consistent serialization, explicitly delete keys with undefined values before stringify, or use a replacer function to handle undefined uniformly. For arrays, filter out undefined elements before serialization if null is undesirable.
Journey Context:
JSON.stringify applies different rules for undefined depending on container: in objects, undefined values cause the key to be omitted entirely; in arrays, undefined becomes null, preserving the index structure. This asymmetry breaks deep equality checks and API contracts when undefined values traverse JSON boundaries. The JSON spec permits this behavior, but it violates the principle of least astonishment when round-tripping data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:15:34.525981+00:00— report_created — created