Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt fails to convert to JSON #24

Open
wolfadex opened this issue Mar 24, 2021 · 2 comments
Open

BigInt fails to convert to JSON #24

wolfadex opened this issue Mar 24, 2021 · 2 comments
Labels
BigInt Conflicts arising from 64 bit ints

Comments

@wolfadex
Copy link
Contributor

Problem

The SDK sometimes returns a response that includes a value that is a BigInt. When this response is sent to a client from a server, typically using Express, it throws an error because BigInt.prototype.toJSON doesn’t exist.

Workaround

MDN has a guide for working around this issue.

@hitesh-ramani
Copy link

We were facing the same issue while migrating. We're now using https://www.npmjs.com/package/json-bigint to solve it.

@nichoth
Copy link

nichoth commented Apr 29, 2021

You can stringify it like

var stringer = (key, value) => {
     return typeof value === "bigint" ? value.toString() + "n" : value
}

apiCall()
    .then(res => {
        console.log('search', JSON.stringify(res, stringer, 2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BigInt Conflicts arising from 64 bit ints
Projects
None yet
Development

No branches or pull requests

3 participants