3 ms·
Makes sense for the most part with these constraints then. I missed the "primitive types" portion in the original comment. The following isn't applicable for p
by nishs 4y ago
Makes sense for the most part with these constraints then. I missed the "primitive types" portion in the original comment.
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.