README
json-cycle
Utilities provide ability to encode/decode circular structures for converting to and from JSON.
Based on JSON-js
Install
In your project:
npm install json-cycle --save
Details
This package contains four functions, decycle, retrocycle, stringify and parse, which make it possible to encode cyclical structures and convert them to JSON, and then recover them. This is a capability that is not provided by ES5. JSONPath is used to represent the links. [http://GOESSNER.net/articles/JsonPath/]
Note: If you stringify javascript structure and then parse it back in some cases you can get not the same javascript structure. For instance, if it contains Date object you get String form of it.
Methods
decycle(object)
Note:
decycle
function makes a deep copy of any provided structure while originaldecycle
function from JSON-js does not make copy forBoolean
,Date
,Number
,RegExp
andString
objects.
Makes a deep copy of an provided structure with resolving all circular references. The duplicate references which part of an cycle are replaced with an object of the form
{$ref: PATH}
where the PATH is a JSONPath string that locates the first occurrence.
Example:
jc = require('json-cycle');
var a = {};
a.self = a;
console.log(JSON.stringify(jc.decycle(a)));
Output:
{{"$ref":"