circular JSON 🟨 JavaScript

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

  1. Stringify only the fields you need
  2. Use a replacer that skips seen objects
  3. Use util.inspect or console.dir for logging

Detailed fix by platform

JavaScript

  1. 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

  1. Object — Which object (the message names the path)?
  2. 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.