Preliminary tl;dr: are circular references normally allowed in JSON? And if so, how is it, algorithmically, handled on both ends of a typical browser + AJAX + serverside setup?
A little background
Out of curiosity to see if I could do it, and also because I'm not overly happy with the interface of the standard(?) JSON modules out there, I decided to roll my own Perl-to-JSON module (and plan to include a JSON-to-Perl part too, but that's another issue).
Halfway through getting something working surprisingly well, I wondered if it would work if I threw something with a circular reference at it. It did what I expected and hurled itself into an endless loop. Not good, so for the time being I slapped a maximum depth onto it.
That's only a half-assed solution, of course, so I put myself to some research - how does JSON normally "handle" circular references? It didn't take me long to stumble upon the RFC and it doesn't make mention of any such thing.
In conclusion
So, in conclusion, my questions:
- does JSON normally allow circular references?
- If it does, how do client side implementations (specifically webbrowsers' native JSON libraries or JavaScript libraries such as jQuery et al.) and server side implementations do it?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.