How safe-stable-stringify differs from JSON.stringify
mainWhile safe-stable-stringify is side-effect free and supports toJSON(), replacer, and space exactly like JSON.stringify(), there are four key differences:
- Circular values: Replaced with a configurable string (defaulting to
[Circular]) instead of throwing. - Object keys: Sorted by default to ensure deterministic output (configurable).
- BigInt: Serialized as a regular number (default) or string instead of throwing a
TypeError. - Boxed primitives: Values like
Number(5)are treated as regular objects and are not unboxed.