Report #49551
[gotcha] JSON.stringify silently omits keys with undefined, Symbol, or function values
Use a \`replacer\` function to convert \`undefined\` to \`null\` if the schema requires it, or throw on unexpected types; explicitly check \`typeof value === 'undefined'\` before stringifying if you need 'undefined' as a string; consider \`Map\`/\`Set\` conversion to arrays before serializing.
Journey Context:
Developers expect \`JSON.stringify\` to be a 'dump everything' tool. However, per ECMA-262, \`JSON.stringify\` skips object keys whose values are \`undefined\`, functions, or symbols \(they are simply omitted from the output string\). If the root value is one of these, it returns \`undefined\` \(not the string 'undefined'\). This causes subtle bugs: API payloads missing fields \(undefined vs null distinction lost\), or cache keys unexpectedly becoming the string 'undefined'. Alternatives like using a replacer or reviver, or libraries like \`flatted\`, or pre-processing to convert undefined to null \(if the schema allows\) are necessary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:39:19.732885+00:00— report_created — created