
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
fast-safe-stringify
Advanced tools
Safely and quickly serialize JavaScript objects
Detects circular dependencies instead of throwing
(as per usual JSON.stringify
usage)
var safeStringify = require('fast-safe-stringify')
var o = {a: 1}
o.o = o
console.log(safeStringify(o))
console.log(JSON.stringify(o)) //<-- throws
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
.
Sponsored by nearForm
MIT
Similar to fast-safe-stringify, json-stringify-safe provides a way to safely serialize objects into JSON strings, handling circular references by replacing them with a custom string. It's a bit slower compared to fast-safe-stringify but serves a similar purpose.
Flatted is a package that serializes and deserializes JavaScript objects, including nested and circular references. Unlike fast-safe-stringify, which returns a JSON string, Flatted returns a flattened string representation that can be re-parsed into the original object structure, including circular references.
FAQs
Safely and quickly serialize JavaScript objects
The npm package fast-safe-stringify receives a total of 12,470,822 weekly downloads. As such, fast-safe-stringify popularity was classified as popular.
We found that fast-safe-stringify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.