Skip to content
Streaming version of `JSON.stringify` for node.js
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

JSON Streamify

A streaming version of JSON.stringify.

npm install json-streamify


streamify(object, function)

Passes the function chunks of the object until there is none of the object left. streamify is a synchronous function.

var assert = require('assert')
  , streamify = require('../streamify').streamify
  , streamingWrite = require('../streamify').streamingWrite
  , fs = require('fs')
  , object = { a: 1, b: 2, c: 3}

var str = '';
streamify(object, function(data) { str += data; });
// => {"a":1,"b":2,"c":3}

streamingWrite(filepath, object, callback)

Writes chunks of the object to the given filepath until there is none of the object left. When it finishes, it calls callback.

var str = '';
streamingWrite('./ACOOLFILE.txt', object, function(data) { str += data; }, function() {

  // => {"a":1,"b":2,"c":3}

Most of this was written by James Halliday, with a few small things by David Trejo.


  • allow a stream to be passed into streamify(object, stream)?
  • escapes strings correctly
  • throw binary data at it and make sure JSON.parse() doesn't error when you read it back try using this string:

      var s = ''; for (var i = 0; i < 255; i++) { s += String.fromCharCode(i) }

    and maybe this to fix it, along with something else.

      .replace(/\\/gi, '\\\\')
  • fix the tests which fail on the above few todos
Something went wrong with that request. Please try again.