Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yyx990803/circular-json-es6
circular JSON.stringify and JSON.parse, for environments with native ES6 Map
https://github.com/yyx990803/circular-json-es6
Last synced: 9 days ago
JSON representation
circular JSON.stringify and JSON.parse, for environments with native ES6 Map
- Host: GitHub
- URL: https://github.com/yyx990803/circular-json-es6
- Owner: yyx990803
- License: mit
- Created: 2016-03-04T20:43:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-08T03:39:33.000Z (over 6 years ago)
- Last Synced: 2024-08-31T02:52:05.911Z (2 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 129
- Watchers: 5
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-github-star - circular-json-es6
README
# circular-json-es6
A replacement for `JSON.stringify` and `JSON.parse` that can handle circular references (persists reference structure).
**This implementation requires environments with native ES6 Map support,** but is decently faster than [circular-json](https://github.com/WebReflection/circular-json) (see benchmark with `npm run bench`).
``` js
var CircularJSON = require('circular-json-es6')var obj = {}
obj.a = objvar clone = CircularJSON.parse(CircularJSON.stringify(obj))
clone.a === clone // -> true
```### NOTE
The default `stringify` method optimizes for cases where no circular reference is present by trying a plain `JSON.stringify` first. This means if no circular references are found in the data then it will not persist multiple (but non-circular) references to the same object.
If you want to enforce reference persistence, use `CircularJSON.stringifyStrict` instead.