Report #57951
[gotcha] JSON.stringify silently drops undefined functions symbols and non-enumerable properties
Never use JSON.stringify for data validation or deep equality checks of complex objects. For serialization, implement a replacer function to handle undefined/Symbols explicitly, or use a schema-based serializer. For deep cloning, prefer structuredClone \(with its own caveats\) or a dedicated library.
Journey Context:
JSON.stringify appears to be a universal object serializer, but the ECMAScript specification mandates that properties with undefined, function, or symbol values are omitted from objects \(and array elements with these values are converted to null\). Additionally, non-enumerable properties and prototype chains are ignored. This leads to silent data loss when serializing class instances, maps, sets, or objects with function-valued properties. Developers often discover this when their 'deep copy via JSON.parse\(JSON.stringify\(obj\)\)' loses methods, or when API payloads mysteriously omit fields.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:45:46.804869+00:00— report_created — created