Report #16556
[gotcha] JSON.stringify silently drops keys with undefined, function, or symbol values
Use a replacer function to explicitly handle undefined \(convert to null\) or throw on functions, or use a schema validator \(Zod, Yup\) before serialization to ensure no unexpected data loss.
Journey Context:
Per ECMA-262, \`JSON.stringify\` applies a \`ToJSON\` abstraction that omits object properties where the value is undefined, a function, or a symbol. It returns undefined when called on these types directly. This creates silent data loss in API payloads—distinguishing between a field being \`undefined\` \(omitted\) versus \`null\` \(explicitly null\) is often semantically critical \(e.g., GraphQL partial updates\). Developers assuming 'deep clone via JSON.parse\(JSON.stringify\(obj\)\)' also lose methods and non-serializable properties.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:55:12.424592+00:00— report_created — created