TypeError: Converting circular structure to JSON
JSON.stringify met an object that references itself (directly or through children).
Seen on:
JavaScript
Meaning
DOM nodes, framework objects (Express req/res, Mongoose docs), and parent↔child links create cycles that JSON can’t represent.
Common causes
- Logging/stringifying req/res or DOM elements
- Parent/child references in your data
- ORM documents with back-references
⚡ Quick fix
- Stringify only the fields you need
- Use a replacer that skips seen objects
- Use util.inspect or console.dir for logging
Detailed fix by platform
JavaScript
- javascript
const seen = new WeakSet(); JSON.stringify(obj, (k, v) => (typeof v === 'object' && v !== null ? (seen.has(v) ? undefined : (seen.add(v), v)) : v));
How to diagnose
- Object — Which object (the message names the path)?
- Need — Do you really need the whole object?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026