Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

circular-to-json

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

circular-to-json

Convert your Circular structure to a JSON string very easily and very accurate

  • 1.0.2
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

CircularToJSON

circular-to-json is a JavaScript library that provides a way to convert circular data structures to JSON format, allowing you to serialize and store data in a format that can be easily transmitted and used by other applications.
With circular-to-json, you can easily convert JavaScript objects that contain circular references to a JSON string, without losing any of the data or structure. This is particularly useful when working with complex data structures, such as graphs, trees, and other recursive data types.

The library provides two main functions:

  • stringify(obj, [replacer], [space]): Converts an object to a JSON string, handling circular references with a replacer function that removes the circular

  • parse(json, [reviver]): Converts a JSON string to an object, handling circular references by restoring the original references.

The library is lightweight and easy to use, with no external dependencies. It works in both browser and Node.js environments, making it ideal for a wide range of applications.

Installation

You can install using NPM or Yarn:

  npm i circular-to-json

  yarn add circular-to-json

Usage

Import

import CircularJSON from "circular-to-json"
const CircularJSON = require("circular-to-json")

stringify function:

const obj = {
  prop1: "value1",
  prop2: "value2"
};

obj.circularRef = obj; // adding circular reference

const jsonString = CircularJSON.stringify(obj);
console.log(jsonString);

Output
{"prop1":"value1","prop2":"value2","circularRef":{"[Circular]":""}}

parse function:

const jsonString = '{"prop1":"value1","prop2":"value2","circularRef":{"[Circular]":""}}';
const obj = CircularJSON.parse(jsonString);

console.log(obj.prop1); // Output: value1
console.log(obj.circularRef === obj); // Output: true

Contributing

circular-to-json is an open-source project, and we welcome contributions from the community.

Licence

CircularJSON is licensed under the MIT License.

Keywords

FAQs

Package last updated on 29 Mar 2023

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