Unexpected token with valid json?

Why can't I print this simple json? jsonlint.com says it really

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 following 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

+5
source share
1 answer

Since the JSON parser in Node require() accepts ASCII characters, and your example contains the Unicode character: If you replace all instances with \u2026 , your JSON should parse.

+6
source

Source: https://habr.com/ru/post/1245935/


All Articles