2

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?

4
  • Is it possible to have a circulative structure in JSON? I thought Crockford did a talk where he explicitly said those couldn't be done. Commented Oct 24, 2011 at 18:13
  • if you can serialize the object, than you can stringify it. If object can't be serialized than it can't be stringify. Commented Oct 24, 2011 at 18:19
  • It is possible. Default req object in node.js or any DOM object contains circulative structure. how to serialize the object? Commented Oct 24, 2011 at 18:24
  • 1
    You might be confusing JSON with JavaScript objects. JSON is a subset of JavaScript. Native objects can do things that JSON can't. Commented Oct 24, 2011 at 18:25

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.