Fix lỗi unexpected token f in json at position 192 năm 2024

If you are coding in JavaScript, React, or any other JavaScript library/framework, you would have come across the following errors:

SyntaxError: Unexpected token < in JSON at position 0

SyntaxError: Unexpected end of JSON input

When does this error occur?

This error occurs when you are trying to parse a string to JSON and the string is not parsable. In other words, it happens when you pass an invalid JSON string to JSON.parse[] function.

Try executing the following code in the browser console:

JSON.parse[""]

Enter fullscreen mode Exit fullscreen mode

You will see the following error:

So the error is telling that it is seeing a string

Chủ Đề