faster-stable-stringify

Faster deterministic JSON.stringify() without bells and whistles.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
faster-stable-stringify
211.0.07 years ago7 years agoMinified + gzip package size for faster-stable-stringify in KB

Readme

faster-stable-stringify
Faster deterministic JSON.stringify() without bells and whistles.
const stableStringify = require('faster-stable-stringify');

const json = stableStringify({greetings: 'Hello!', apples: 'bananas'});
// json = {"apples":"bananas","greetings":"Hello!"}

Installation

$ npm install faster-stable-stringify

Features

  • JSON.stringify that has deterministic output
  • Handles edge cases in accordance with the spec
  • Replaces cycles with "[Circular]" similar to isaac's
json-stringify-safe1

API

A single function is exported.
stableStringify(value)

The behavior is identical to the native JSON.stringify, excluding circular structures. See here2 for an explanation of the JSON.stringify behavior.
Alternatives
If you need to customize the sorting behavior, or want an implementation that throws on circular references, you may prefer to use substack's json-stable-stringify3.
If you need it to work in the browser or in an environment without a native JSON.stringify, you may prefer to use nickyout's fast-stable-stringify4.