Skip to content

Instantly share code, notes, and snippets.

@DTrejo
Created April 4, 2011 22:09
Show Gist options
  • Save DTrejo/902567 to your computer and use it in GitHub Desktop.
Save DTrejo/902567 to your computer and use it in GitHub Desktop.
seems not to work... Why?
var obj = { "tricky": 'these "tick∫."' };
var str = '';
//
// npm install json-streamify
//
require('json-streamify').streamify(obj, function(data) { str += data; });
console.log('%s', str);
console.log('%s', JSON.stringify(obj));
console.log();
console.log(JSON.parse(str));
console.log(JSON.parse(JSON.stringify(obj)));
console.log(JSON.parse(JSON.stringify(obj)) == JSON.parse(str)
, 'Properly parses strings');
console.log('casting to buffers to see what happens');
var buf1 = new Buffer(str, 'utf8');
var buf2 = new Buffer(JSON.stringify(obj));
console.log(buf1);
console.log(buf2);
console.log(buf1 === buf2, 'buffs equal');
console.log(buf1.toString('utf8') === buf2.toString('utf8'), 'strings equal');
//
// Yields
//
// {"tricky":"these \"tick∫.\""}
// {"tricky":"these \"tick∫.\""}
//
// { tricky: 'these "tick∫."' }
// { tricky: 'these "tick∫."' }
// false 'Properly parses strings'
// casting to buffers to see what happens
// <Buffer 7b 22 74 72 69 63 6b 79 22 3a 22 74 68 65 73 65 20 5c 22 74 69 63 6b e2 88 ab 2e 5c 22 22 7d>
// <Buffer 7b 22 74 72 69 63 6b 79 22 3a 22 74 68 65 73 65 20 5c 22 74 69 63 6b e2 88 ab 2e 5c 22 22 7d>
// false 'buffs equal'
// true 'strings equal'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment