AceDevHub
Intermediate JavaScript Interview QuestionsIntermediateConcept

JavaScript · Question 57

What are important limitations of JSON.stringify() and JSON.parse()?

Direct answer

JSON serialization supports JSON-compatible data, not arbitrary JavaScript object semantics; some values are omitted or transformed, BigInt and cycles need special handling, and prototypes/methods are not reconstructed by JSON.parse().

JSON is a data interchange format. Treating JSON.parse(JSON.stringify(value)) as a universal object clone loses information because JavaScript contains many values that JSON cannot represent directly.

  • undefined, functions, and symbols are not represented as normal object property values in the resulting JSON.
  • NaN and infinities serialize as null.
  • Date typically becomes a string through its JSON conversion behavior rather than remaining a Date object after parsing.
  • Map and Set do not automatically become their logical entries without custom conversion.
  • Cyclic object graphs throw unless you design a replacer/serialization scheme that handles references.
  • BigInt is not directly JSON-serializable without custom handling.

Use replacer/reviver functions or an application-specific schema when values need controlled conversion. For data interchange, explicit schemas are often more reliable than hoping arbitrary runtime objects round-trip.