Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

fast-safe-stringify

Package Overview
Dependencies
Maintainers
2
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

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
16M
-17.07%
Maintainers
2
Weekly downloads
 
Created
Source

fast-safe-stringify

Safely and quickly serialize JavaScript objects

Detects circular dependencies instead of throwing (as per usual JSON.stringify usage)

Usage

var safeStringify = require('fast-safe-stringify')
var o = {a: 1}
o.o = o

console.log(safeStringify(o))
console.log(JSON.stringify(o)) //<-- throws

Benchmarks

The json-stringify-safe module supplies similar functionality with more info and flexibility.

Although not JSON, the core util.inspect method can be used for similar purposes (e.g. logging) and also handles circular references.

Here we compare fast-safe-stringify with these alternatives:

inspectBench*10000: 132.456ms
jsonStringifySafeBench*10000: 67.382ms
fastSafeStringifyBench*10000: 31.672ms

inspectDeepBench*10000: 1632.687ms
jsonStringifySafeDeepBench*10000: 1062.449ms
fastSafeStringifyDeepBench*10000: 177.926ms

fast-safe-stringify is 2x faster for small objects, and 6x faster for large objects than json-stringify-safe.

fast-safe-stringify is 4x faster for small objects, and 9x faster for large objects than util.inspect.

Acknowledgements

Sponsored by nearForm

License

MIT

FAQs

Package last updated on 13 Sep 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