What the Error Means
JSON is a tree: every value has one parent. A JavaScript object can point back to itself or to one of its parents, which makes a loop. JSON.stringify would follow that loop forever, so it stops with an error instead:
const user = { name: 'Emily' }
user.self = user
JSON.stringify(user)TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
--- property 'self' closes the circleFirefox words it as TypeError: cyclic object value and Safari as JSON.stringify cannot serialize cyclic structures. Same problem.
Read the Message: It Shows the Loop
Chrome and Node.js print the path of the loop. For a team whose member points back to the team:
const team = { name: 'Team' }
const member = { name: 'Emily', team }
team.members = [member]
JSON.stringify(team)TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'members' -> object with constructor 'Array'
| index 0 -> object with constructor 'Object'
--- property 'team' closes the circleRead it top to bottom: team.members[0].team points back to team. That is the property to leave out, or the place to change your data.
Where Circular Objects Come From
- Parent and child links in your own data, like the example above, or trees where nodes keep a
parentreference. - DOM elements and browser events. An element links to its parent and its document. Log
event.target.value, not the event. - HTTP library objects. Request, response and error objects (from fetch, Axios, Express or Node's
httpmodule) hold sockets and links to each other. Send or logresponse.dataorerror.message, not the whole object. - ORM documents and class instances that keep references to their connection or model. Convert them to plain data first, for example with the library's
toObject()ortoJSON()method.
Fix 1: Send Only the Data You Need
The best fix is usually to stop stringifying the big object and pick the plain values:
JSON.stringify({ name: member.name, team: member.team.name })
// {"name":"Emily","team":"Team"}Or drop the problem key with a replacer function:
JSON.stringify(member, (key, value) => (key === 'team' ? undefined : value))
// {"name":"Emily"}Fix 2: Replace Loops with "[Circular]"
For logging or debugging, a replacer can mark repeated parents instead of failing. Many snippets online use a WeakSet of every object seen, but that also hides objects that are simply used twice without any loop. Our test with the same address object in two places:
const address = { city: 'London' }
safeStringify({ home: address, work: address })
// {"home":{"city":"London"},"work":"[Circular]"} ← work lost its dataThis version only marks real loops, by tracking the chain of parents of the current value:
function stringifyWithoutCycles(value, space) {
const parents = []
return JSON.stringify(value, function (key, val) {
if (typeof val !== 'object' || val === null) return val
// "this" is the object that holds the current key: drop parents we have left.
while (parents.length && parents[parents.length - 1] !== this) parents.pop()
if (parents.includes(val)) return '[Circular]'
parents.push(val)
return val
}, space)
}
stringifyWithoutCycles({ home: address, work: address })
// {"home":{"city":"London"},"work":{"city":"London"}}
stringifyWithoutCycles(team)
// {"name":"Team","members":[{"name":"Emily","team":"[Circular]"}]}Use a regular function, not an arrow function, so that this is the parent object. The result is valid JSON, but the loops are gone, so it cannot be turned back into the original object.
Fix 3: Logging Without JSON
If you only want to look at the object, you may not need JSON at all. console.log(user) handles loops, and in Node.js util.inspect marks them:
import { inspect } from 'node:util'
inspect(user)
// <ref *1> { name: 'Emily', self: [Circular *1] }To copy an object with loops, structuredClone(user) works and keeps the loop, while JSON.parse(JSON.stringify(user)) throws.
The Other JSON.stringify Error: BigInt
JSON.stringify({ id: 12345678901234567890n })
// TypeError: Do not know how to serialize a BigIntJSON has no BigInt type. Turn it into a string, which keeps every digit:
JSON.stringify(data, (key, value) => (typeof value === 'bigint' ? value.toString() : value))
// {"id":"12345678901234567890"}Values JSON.stringify Changes Without Warning
No error here, but the result is not what many people expect. All tested in Node.js 24:
| Input | Output |
|---|---|
{ a: undefined, b: () => 1, d: 1 } | {"d":1}: undefined, functions and symbols are dropped from objects |
[undefined, () => 1, 2] | [null,null,2]: in arrays they become null |
{ n: NaN, i: Infinity } | {"n":null,"i":null} |
new Date(...) | "2026-11-23T09:30:00.000Z": a string, not a Date, after parsing |
new Map([['a', 1]]), new Set([1, 2]) | {}: empty objects. Use Object.fromEntries(map) and [...set] |
JSON.stringify(undefined) | undefined, not a string |
A class can decide how it is written by adding a toJSON() method; for a point with toJSON() { return [this.x, this.y] } the output was [1,2]. More on both directions in JSON.parse and JSON.stringify in JavaScript.
Frequently Asked Questions
What does Converting circular structure to JSON mean?
The object you passed to JSON.stringify points back to itself or to one of its parents. JSON cannot represent a loop, so JSON.stringify throws a TypeError. Chrome and Node.js show the property that closes the circle.
How do I fix TypeError: Converting circular structure to JSON?
Stringify only the plain data you need, drop the looping key with a replacer function, or use a replacer that writes "[Circular]" for real loops. For logging, console.log or util.inspect handle loops without JSON.
Why does a WeakSet replacer mark non-circular objects as [Circular]?
A WeakSet remembers every object already written, so an object used in two places is marked the second time even without a loop. Track only the chain of parent objects to mark real loops.
How do I stringify a BigInt?
JSON has no BigInt type, so JSON.stringify throws Do not know how to serialize a BigInt. Use a replacer that returns value.toString() for bigint values to keep every digit.