Home > OS >  Firebase Cloud Function Data cannot be encoded BigInt
Firebase Cloud Function Data cannot be encoded BigInt

Time:10-26

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.

https://golb.hplar.ch/2018/09/javascript-bigint.html#json

  • Related