Reputation:
Why can't I print this simple json? jsonlint.com says this is valid
json:
[
{
"token_start_offset": "0.00",
"token_duration": "4.00",
"token_base_start_offset": "0.00",
"token_base_duration": "4.00",
"token_type": "background_noise",
"token_background_noise_type": "other",
"session_id": "1459194633575",
"token_base_form": "…",
"token_print_form": "…",
"session_boundary": "begin",
"nonspeech_boundary": "begin",
"token_id": "0"
}
]
app.js:
var testJson = require('./json');
console.log(testJson);
But when I run this, I get the below error:
Error:
module.js:428
throw err;
^
SyntaxError: C:\Users\Owner\Desktop\format test\json.json: Unexpected token
at Object.parse (native)
at Object.Module._extensions..json (module.js:425:27)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Owner\Desktop\format test\app.js:1:78)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
Windows 10 node -v 4.2.6
Upvotes: 5
Views: 3158
Reputation: 17377
Because the JSON parser in Node's require()
assumes ASCII characters and your example contains a Unicode character: …
. If you replace all instances of …
with \u2026
, your JSON should parse.
Upvotes: 6