This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
canonical-json with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
The goal of this module is to implement a version of JSON.stringify that returns a canonical JSON format.
Canonical JSON means that the same object should always be stringified to the exact same string.
Properties of non-array objects are not guaranteed to be stringified in any particular order. Do not rely on ordering of properties within the same object within the stringification.
This module implements two alternative solutions to this problem:
It currently exports the index.js version.
##Performance comparison I compared the performance of native JSON.stringify and the two alternative implementations that output keys sorted:
The tests were run in Node.js on a 2011 MacBook Pro.
Performance test source: test/performance.js