New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-decycle

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-decycle

(es6) stringify and parse cycled reference json

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by42.01%
Maintainers
1
Weekly downloads
 
Created
Source

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('../index').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 === require('json-decycle').decycle
JSON.retrocycle === require('json-decycle').retrocycle

ES6 features

Library depends on es6 features WeakMap, WeakSet and Set so if you environment does not support this features, you can override it:


var jsonDecycle = require('json-decycle')

jsonDecycle.WeakMap = WeakMap
jsonDecycle.WeakSet = WeakSet
jsonDecycle.Set = Set

Keywords

FAQs

Package last updated on 10 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc