How to find a circular reference in a js object?

Encountered an error TypeError: Converting circular structure to JSON , read the manuals, write the following:

JavaScript frameworks containing circular references cannot be serialized using the "simple" JSON.stringify

found a place that is called JSON.stringify and see what comes to him at the entrance. And here comes such an object joxi.ru/LmGVz1nSe8Glkr received after the call I might have something not understand, but where is the circular reference?

The JSON itself looks like this:

{
"price_raw": 209,
"card_discount": 0,
"event_discount": 0,
"summ": 209,
"shop_url": "\/customers\/shops\/detail\/84862\/",
"favUrl": "\/local\/templates\/am\/ajax\/favorite.php?type=shop&id=84862",
"favorite": false,
}
June 14th 19 at 19:13
1 answer
June 14th 19 at 19:15
In "shopSiteId" You probably is a jQuery element.
Eliminate it using the second parameter of JSON.stringify.

function replacer(key, value) {
 if (key === 'shopSiteId') {
 return 'jQuery-element'; // or undefined, to completely eliminate
}

 return value;
}

JSON.stringify(data, replacer);
function replacer(key, value) {
 if (value instanceof jQuery) {
 return undefined;
}
 return value;
}


In General, it's not a jQuery object, they are serialized without error, and that TC somehow managed to put into the property context a reference to the first property of this object, i.e. obj.shopSiteId[0] === obj.shopSiteId.context. You can verify somehow so. - gustave_Kertzmann52 commented on June 14th 19 at 19:18

Find more questions by tags JavaScriptjQueryJSON