Handle JSON serialization of objects that contain circular references using cycle.js without getting a TypeError.
Restore circular-reference structures from JSON by decoding the path strings back into live object links.
Safely serialize complex data structures like doubly-linked lists or trees with parent pointers to JSON.
Study how the JSON standard was originally polyfilled for browsers before native support was added in 2009.
This repository is maintained by Douglas Crockford, the person who created the JSON data format. JSON, which stands for JavaScript Object Notation, is the most common way to exchange data between web applications and servers today. It was originally invented as a subset of JavaScript, and this repository contains some of Crockford's original JavaScript implementations related to JSON. The repository includes two files. The first, json2.js, is a historical polyfill: a piece of code that adds JSON support to very old browsers that did not have it built in. Modern browsers have native JSON support built into the language itself, added as a standard feature in 2009. The README states plainly that json2.js does nothing on current browsers and that the only reason to use it would be to support Internet Explorer 8, which it then says no one should ever have to do again. This file is essentially a historical artifact. The second file, cycle.js, is more practically useful in certain situations. It contains two functions for handling circular references in JSON. A circular reference is when an object points back to itself somewhere in its structure, like a tree node that has a reference to its own parent. Standard JSON cannot represent circular references and will throw an error when you try to convert such a structure. cycle.js adds the ability to encode those structures by replacing the circular links with path strings, and to decode them back when reading the data. This is a small, focused utility repository with no build process and no dependencies. Its significance comes mainly from its author and its role in the early history of JSON as a standard.
← douglascrockford on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.