Created
April 4, 2011 22:09
-
-
Save DTrejo/902567 to your computer and use it in GitHub Desktop.
seems not to work... Why?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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