Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Created December 8, 2010 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolaj86/733715 to your computer and use it in GitHub Desktop.
Save coolaj86/733715 to your computer and use it in GitHub Desktop.
JSON parse error
test-fail.js passes jslint.com, fails jsonlint.com, and fails to parse with Node.js JSON.parse.
{
"ID3v1": {
"title": "Michael Bolton \'\' Said i lov",
"artist": "Michael Bolton \'\' Said i lov",
"genre": "Blues"
}
}
{
"ID3v1": {
"title": "Michael Bolton '' Said i lov",
"artist": "Michael Bolton '' Said i lov",
"genre": "Blues"
}
}
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