Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

All the data comes from a JSON API and thus doesn't contain Date objects to begin with.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: