Search code examples
javascriptnode.jsstringify

JSON.stringify doesn't work in circulative JSON object. What to do?


e.g., in Node.js, if I do this:

JSON.stringify(req); 

Then I will fail because of circulative structure.

is there any setting or way to stringify it easily and skip the circulative part of structure?


Solution

  • Crockford's library (see cycle.js) https://github.com/douglascrockford/JSON-js supports encoding and decoding of circular objects into json (+ jsonpath).