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

Time:01-24

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?

CodePudding user response:

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".

  •  Tags:  
  • json
  • Related