JSPM

  • Created
  • Published
  • Downloads 14930956
  • Score
    100M100P100Q224893F
  • License MIT

Safely and quickly serialize JavaScript objects

Package Exports

  • fast-safe-stringify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-safe-stringify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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: 155.304ms
jsonStringifySafeBench*10000: 86.004ms
fastSafeStringifyBench*10000: 39.039ms
inspectBench*10000: 133.499ms
jsonStringifySafeBench*10000: 74.028ms
fastSafeStringifyBench*10000: 38.698ms

fast-safe-stringify is 2x faster than json-stringify-safe and 3x-4x faster than util.inspect.

Acknowledgements

Sponsored by nearForm

License

MIT