Using JSON.stringify() on an object that contains cyclical references

I created a Building object that had a 'marker' property (and some other properties). The 'marker' property contained a Google Map Marker, and I'm not sure of it's internals, but when I tried to use JSON.stringify() on it, I got a 'cyclic object value' error. After digging around, I found that you can pass in a second param to stringify(), which is a function that you can use to override the values of properties in the output string. In this case I used it to exclude the marker property from the string.

 

var json = JSON.stringify(buildingObj, function(key,value){
    if(key == "marker"){
        return undefined;
    }
    return value;
});

Add a Comment...

 

Comments

That's the most lazy and lame solution of all times. Just try to apply your solution to window object in case you want to JSON.stringify(window) from inside an iframe. - 9/04/2016

An impressive share! I have just forwarded this onto a colleague who has been conducting a little research on this. And he in fact ordered me breakfast due to the fact that I stumbled upon it for him... lol. So let me reword this.... Thanks for the meal!! But yeah, thanks for spending the time to discuss this topic here on your website. - 8/30/2016

best mattress in 2017 best mattresses in 2017 macy mattress sale 2017 best mattress of 2017 for side sleeper best rated hybrid mattresses 2017 the best rated mattress 2017 best mattresses 2017 for couples best mattress to buy 2017 top rated mattresses for 2017 best mattress to buy for 2017 mattress ratings 2017 the best mattresses 2017 best mattresses for 2017 best mattresses for 2017 top ten mattresses 2017 casper promo code 75 casper dog bed coupon casper com promo code printable l - 7/22/2017

Absolutely NEW update of SEO/SMM software "XRumer 16.0 + XEvil 3.0": captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another categories of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? You can find a lot of introducing videos about XEvil in YouT - 7/22/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captchas recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another size-types of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of impessive videos about XEvil in YouT - 7/22/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captchas solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? There are a lot of impessive videos about XEvil in YouTube. Go - 7/22/2017

Absolutely NEW update of SEO/SMM software "XRumer 16.0 + XEvil 3.0": captchas recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? There are a lot of introducing videos about XEvil in YouT - 7/21/2017

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil": captcha regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of introducing videos about XEvil in YouTube. - 7/18/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captchas recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? You can find a lot of demo videos about XEvil in YouTube. G - 7/18/2017

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another size-types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of introducing videos about XEvil in YouTube. - 7/17/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captchas regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of impessive videos about XEvil in YouTube. - 7/14/2017

Several phrases & words demand such incredibly high ‘click’ prices that profit margins aren’t feasible for a lot of institutions.au to know more about asian escorts sydney. Cheap NFL Jerseys. Work the soil beneath this depth, as directed above. Because estrogen and testosterone levels drop naturally and dramatically in equally women and males when they age, taking drugs to restore the natural balance of the hormones is vital to maintaining the libido. The Magento system is the greatest - 7/07/2017

How to determine if Javascript array contains an object with an attribute that equals a given value? - Stack Overflow - 6/07/2017

It s useful to point out that under the hood, these are all looping. These are also all slower computationally than simply for looping and performing operations. - 6/05/2017

How to determine if Javascript array contains an object with an attribute that equals a given value? - Stack Overflow - 6/05/2017

Have you ever considered publishing an ebook or guest authoring on other websites? I have a blog based upon on the same subjects you discuss and would really like to have you share some stories/information. I know my subscribers would enjoy your work. If you're even remotely interested, feel free to shoot me an e-mail. - 3/25/2017

ER - 2/22/2017

block out this online casinos where you can conquer legal kale with the usurp of this guidebookPlaying free casino games - 2/16/2017

Attractive section of content. I just stumbled upon your website and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I will be subscribing to your feeds and even I achievement you access consistently rapidly. - 12/01/2016

This info is worth everyone's attention. When can I find out more? - 11/17/2016

I was wondering if you ever looked at changing the page layout of your own blog? Its adequately written; I really like what youve have got to say. But maybe you could a bit more when it comes to content so people could connect with it better. Youve got so much of text for only having 1 or two pictures. You could possibly could space it all out better? - 10/07/2016