I am specifically working with the Square API where they regularly use the bigint type. Is there an easy way to encode this bigint as a String?
Error:
Data cannot be encoded in JSON. 1634864610834n
CodePudding user response:
You can check for BigInt
and convert to/from a string by passing a closure as the second argument to the JSON.stringify()
and JSON.parse()
methods. Here's a great article with more info.