A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_not_serializable below:

TypeError: BigInt value can't be serialized in JSON - JavaScript

TypeError: BigInt value can't be serialized in JSON

The JavaScript exception "BigInt value can't be serialized in JSON" occurs when a BigInt is encountered in JSON.stringify with no custom serialization method provided.

Message
TypeError: Do not know how to serialize a BigInt (V8-based)
TypeError: BigInt value can't be serialized in JSON (Firefox)
TypeError: JSON.stringify cannot serialize BigInt. (Safari)
Error type What went wrong?

You are trying to serialize a BigInt value using JSON.stringify, which does not support BigInt values by default.Sometimes, JSON stringification happens implicitly in libraries, as part of data serialization. For example, sending data to the server, storing it in external storage, or transferring it between threads would all require serialization, which is often done using JSON.

There are several ways to handle this:

For more information on various tradeoffs, see BigInt reference.

Examples Providing a custom serialization method

By default, BigInt values are not serializable in JSON:

const data = { a: 1n };
JSON.stringify(data);
// TypeError: BigInt value can't be serialized in JSON

Assuming you intend for the JSON to contain a number value, here are a few approaches that work:

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4