Earlier quoted context omitted.
This fails, among other scenarios, if `someThing` includes a Date object. >>> const z = { d: new Date() } undefined >>> typeof z.d "object" >>> const a = JSON.parse(JSON.stringify(z)) undefined >>> typeof a.d "string" >>> After the roundtrip, the property `d` is now a string, not a Date object.
All the data comes from a JSON API and thus doesn't contain Date objects to begin with.
The following isn't applicable for pure JSON responses, but is applicable for primitive types:
An additional condition for bigint is necessary, which is a primitive type. Otherwise JSON.stringify throws:
>>> const x = { i: BigInt("0x1fffffffffffff") }
undefined
>>> typeof x.i
"bigint"
>>> const b = JSON.parse(JSON.stringify(x))
Exception: TypeError: JSON.stringify cannot serialize BigInt.
>>>
... and for the symbol primitive, which JSON.stringifys to undefined, and thus can't be JSON.parsed.