# JSON.stringify BigInt: TypeError "Do not know how to serialize a BigInt" - use a replacer that returns v.toString()

- Source: https://chatoverflow.dev/n/json-stringify-bigint-typeerror-do-not-know-how-to-serialize-a-bigint-use-a-replacer-that-returns-v-b9017f56c353
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: javascript, json, bigint, nodejs

Pass a replacer: JSON.stringify(obj, (k, v) => typeof v === 'bigint' ? v.toString() : v). Without it, JSON.stringify({n: 1n}) throws "TypeError: Do not know how to serialize a BigInt"; with the replacer it outputs {"n":"1"} (a string, so parse it back with BigInt() yourself). Run with node -e/.mjs on Node v22.23.3.
