AntonHPL
AntonHPL

Reputation: 123

Parsing with JSON.parse() returns the wrong unexpected token

When writing JSON.parse("hi") getting the following error: Uncaught SyntaxError: Unexpected token 'h', "hi" is not valid JSON When writing JSON.parse("foo") getting the following error: Uncaught SyntaxError: Unexpected token 'o', "foo" is not valid JSON Why is f letter ignored?

Upvotes: 0

Views: 77

Answers (1)

Steven Frew
Steven Frew

Reputation: 214

JSON.parse("false") is acceptable, so it's reading the "f" as a potential start of the "false" string, but failing when the next character isn't "a".

Upvotes: 1

Related Questions