Skip to content

circular JSON.stringify and JSON.parse, for environments with native ES6 Map

Notifications You must be signed in to change notification settings

Akryum/circular-json-es6

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (see benchmark with npm run bench).

var CircularJSON = require('circular-json-es6')

var obj = {}
obj.a = obj

var 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.

About

circular JSON.stringify and JSON.parse, for environments with native ES6 Map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%