Package Exports
- json-decycle
- json-decycle/index
- json-decycle/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-decycle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
json-decycle (es6)
Stringify and parse cycled reference json by replacing cycled references to JSON-reference
Usage
var decycle = require('json-decycle').decycle
var retrocycle = require('json-decycle').retrocycle
var cycled = {
foo: {},
bar: {}
}
cycled.foo.bar = cycled.foo
cycled.bar.foo = cycled.bar
var result = JSON.stringify(cycled, decycle())
// result === '{"foo":{"bar":{"foo":{"$ref":"#/foo"}}},"bar":{"$ref":"#/foo/bar"}}'
JSON.parse(result, retrocycle())
// => {foo: {{foo: [cyclic reference], bar: [cyclic reference]}}, bar: {{foo: [cyclic reference], bar: [cyclic reference]}}}
Extend JSON global object
JSON.parse
and JSON.stringify
is not modified
require('json-decycle').extend(JSON)
JSON.decycle({}) === '{}'
JSON.retrocycle('{}') === {}
ES6 features
Library depends on es6 features Map
, WeakMap
, WeakSet
and Set
so if you environment does not support this features, you can override it:
const jsonDecycle = require('json-decycle')
jsonDecycle.Map = Map
jsonDecycle.WeakMap = WeakMap
jsonDecycle.WeakSet = WeakSet
jsonDecycle.Set = Set