JavaScript JSON encoder/decoder that preserves precision.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
benchmarks add benchmarks Feb 21, 2011 add Benchmarks and Changelog to README Feb 21, 2011
decimaljson.js remove console.log Apr 25, 2011
package.json 0.2.2 Apr 25, 2011


Very simple JSON parser that preserves the full precision of numbers. It is a fork of json_parse.js from JSON-js. This module should work in browsers and any CommonJS system (tested with Node.js)

Numbers will be parsed into a Decimal class, with .string and .number attributes


For Node.js:

npm install decimaljson

For browser use:

<script src='decimaljson.js' />
<!-- DJSON will be available as a global now -->


// Only for Node.js
> var DJSON = require('decimaljson')

> var array = DJSON.parse('[1.0000000000000001]')
> array
[ Decimal(1.0000000000000001) ]
> array[0].string
> array[1].number


Benchmarks for DJSON.parse and DJSON.stringify are provided. Here are some example results from my laptop:

node 0.2.6 (x86, v8 2.3.8):
  - JSON.parse is 2x faster than DJSON.parse
  - JSON.stringify and DJSON.stringify are the same speed

node 0.4.1 (x86, v8 3.1.5):
  - JSON.parse is 4.5x faster than DJSON.parse
  - JSON.stringify is 3x faster than DJSON.stringify


  • 0.2.0: Added DJSON.stringify. Added benchmarks.
  • 0.1.0: Initial release, DJSON.parse.


  • Try to make a native module for Node.js that uses a modified version of the v8 JSON parser. This is harder than I expected as JSON.parse is implemented by using a special case of the V8 JS parser.