simple-json-circular
v1.1.0
Published
Replaces circular references with JSON path to the first occurence of the object.
Readme
JSON.encodeCirculars
Replaces circular references with JSON path to the first occurence of the object.
Prevents:
> const myArray = [12, 'abc']
undefined
> myArray[2] = myArray
[ 12, 'abc', [Circular] ]
> JSON.stringify(myArray)
TypeError: Converting circular structure to JSONOutputs:
> const myArray = [12, 'abc']
> myArray[2] = myArray
[ 12, 'abc', [Circular] ]
> JSON.encodeCirculars(myArray)
[ 12, 'abc', { '$ref': '$' } ]JSON.decodeCirculars
Replaces JSON paths with referenced object. Outputs:
> const myArray = [ 12, 'abc', { '$ref': '$' } ]
undefined
> JSON.decodeCirculars(myArray)
[ 12, 'abc', [Circular] ]Tests
npm installTo install all dependenciesnpm run testTo run unit tests
