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

fast-safe-stringify

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-safe-stringify

Safely and quickly serialize JavaScript objects

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.3M
decreased by-54.9%
Maintainers
1
Weekly downloads
 
Created

What is fast-safe-stringify?

The fast-safe-stringify package is designed for safely converting JavaScript objects into JSON strings without running into issues like circular references, which can cause the native JSON.stringify to throw an error. It aims to provide a fast and safe way to serialize objects, including those that may contain circular references, functions, and other non-JSON-safe values.

What are fast-safe-stringify's main functionalities?

Safe serialization of circular references

This feature allows you to safely serialize objects that contain circular references, which would otherwise throw an error with JSON.stringify.

const stringify = require('fast-safe-stringify');
const obj = {};
obj.a = { b: obj };
console.log(stringify(obj));

Stable serialization

Provides an option for stable serialization, where the output JSON string's property order is deterministic, making it suitable for hashing, comparisons, etc.

const stringify = require('fast-safe-stringify').stable;
const obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
console.log(stringify(obj));

Serialization with decycler

Allows custom handling of circular references during serialization, enabling you to replace or transform circular references in the resulting JSON string.

const stringify = require('fast-safe-stringify').stable;
function replaceCircular(key, value, circular) { return circular ? '[Circular]' : value; }
const obj = {};
obj.a = obj;
console.log(stringify(obj, replaceCircular));

Other packages similar to fast-safe-stringify

FAQs

Package last updated on 05 Apr 2016

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