Created
December 8, 2010 18:57
-
-
Save coolaj86/733715 to your computer and use it in GitHub Desktop.
JSON parse error
This file contains 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
test-fail.js passes jslint.com, fails jsonlint.com, and fails to parse with Node.js JSON.parse. |
This file contains 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
{ | |
"ID3v1": { | |
"title": "Michael Bolton \'\' Said i lov", | |
"artist": "Michael Bolton \'\' Said i lov", | |
"genre": "Blues" | |
} | |
} |
This file contains 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
{ | |
"ID3v1": { | |
"title": "Michael Bolton '' Said i lov", | |
"artist": "Michael Bolton '' Said i lov", | |
"genre": "Blues" | |
} | |
} |
This file contains 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 fs = require('fs'); | |
function dbgParse(err, json) { | |
var data; | |
try { | |
console.log('input:', json) | |
data = JSON.parse(json); | |
console.log('parsed:'); | |
console.log(data); | |
json = JSON.stringify(data, null, ' '); | |
console.log('stringified:', json); | |
data = JSON.parse(json); | |
} catch (e) { | |
console.log(e); | |
} | |
console.log('\n\n\n'); | |
} | |
fs.readFile('test-pass.json', dbgParse); | |
fs.readFile('test-fail.json', dbgParse); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment