JSON.parse exceptions should have line/char # where parse error occured #1195

broofa opened this Issue Jun 17, 2011 · 3 comments


None yet
2 participants

broofa commented Jun 17, 2011

It would be nice if the error message in the following was, "Unexpected token ILLEGAL @line 3, character 1", instead of just "Unexpected token ILLEGAL".

$ node
> x='{"a":1,\n"b":2,\nc:3}'
> lines = x.split('\n');
[ '{"a":1,', '"b":2,', 'c:3}' ]
> lines[2].indexOf('c')
> JSON.parse(x)
SyntaxError: Unexpected token ILLEGAL
    at Object.parse (native)
    at [object Context]:1:6
    at Interface.<anonymous> (repl.js:171:22)
    at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
    at ReadStream.<anonymous> (readline.js:73:12)
    at ReadStream.emit (events.js:81:20)
    at ReadStream._emitKey (tty_posix.js:307:10)

isaacs commented Jun 17, 2011

Take it up with v8. JSON parse errors just get spit out as-is by node.

isaacs closed this Jun 17, 2011

broofa commented Jun 21, 2011

Isaacs, the V8 folks say line/character information is available from the exception object. Can we reopen this?

See http://code.google.com/p/v8/issues/detail?id=1480

isaacs commented Jun 21, 2011

Commented on the v8 issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment