question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"serialize cyclic structures"

See original GitHub issue

Trying to console.log an object and I just get:

TypeError: JSON.stringify cannot serialize cyclic structures.

@:

at mocha-phantomjs/core_extensions.js:28
at mocha-phantomjs/core_extensions.js:58

We’re using MooTools and I think it might be something to do with trying to stringify a MooTools Class.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paolocarrascocommented, Nov 18, 2013

thanks @nathanboktae! I fixed my problem by using this:

    describe('functionalityToTest', function() {
        var stringify = JSON.stringify;

        before(function() {
            JSON.stringify = function(obj) {
              var seen = [];

              return stringify(obj, function(key, val) {
                 if (typeof val === "object") {
                      if (seen.indexOf(val) >= 0) { return; }
                      seen.push(val);
                  }
                  return val;
              });
            };
        });

        after(function() {
            JSON.stringify = stringify;
        });

        // tests go here
    });
0reactions
nathanboktaecommented, Mar 1, 2016

Yes it is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serializing object that contains cyclic object value
I have an object (parse tree) that contains child nodes which are references to other nodes. I'd like to serialize this object, using...
Read more >
TypeError: cyclic object value - JavaScript - MDN Web Docs
The JavaScript exception "cyclic object value" occurs when object references were found in JSON. JSON.stringify() doesn't try to solve them ...
Read more >
[TypeError: JSON.stringify cannot serialize cyclic structures ...
I'm getting error [TypeError: JSON.stringify cannot serialize cyclic structures.] object when i try to convert realm object to json object ...
Read more >
Random error 'JSON.stringify cannot serialize cyclic structures'
The error was on trying to call the API (Executing the API post method) it failures random on different days only with mobile...
Read more >
React Native JSON.stringify cannot serialize cyclical structures
iOS : React Native JSON.stringify cannot serialize cyclical structures [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found