We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Our volunteers haven't translated this article into עברית yet. Join us and help get the job done!
You can also read the article in English (US).


TypeError: cyclic object value (Firefox)
TypeError: Converting circular structure to JSON (Chrome)

Error type


What went wrong?

When calling JSON.stringify() cyclic object reference structures can't be converted to a string.


In a circular structure like the following

var a = {};
var b = {}; 
a.child = b;
b.child = a;

JSON.stringify() will fail

// TypeError: cyclic object value

You will need to check for cyclic object references before stringifying. For example by specifying a replacer function as the second argument of JSON.stringify().

seen = []; 

var replacer = function(key, value) {
  if (value != null && typeof value == "object") {
    if (seen.indexOf(value) >= 0) {
  return value;

JSON.stringify(a, replacer); 
// "{"child":{}}"

Or, you can use a library or utility functions that have already been written for this scenario. For example, there is cycle.js by Douglas Crockford.

See also

  • JSON.stringify
  • cycle.js – Introduces two functions, JSON.decycle and JSON.retrocycle, which make it possible to encode cyclical structures and dags in JSON, and to then recover them.

Document Tags and Contributors

 Contributors to this page: fscholz
 Last updated by: fscholz,