How to Fix the “SyntaxError: Unexpected token < in JSON at position 0" Error When Developing React Apps?

Sometimes we may run into the “SyntaxError: Unexpected token < in JSON at position 0” error when developing React apps.

In this article, we’ll look at how to fix the “SyntaxError: Unexpected token < in JSON at position 0” error when developing React apps.

Fix the “SyntaxError: Unexpected token < in JSON at position 0” Error When Developing React Apps

To fix the “SyntaxError: Unexpected token < in JSON at position 0” error when developing React apps, we should make sure that we aren’t parsing any JSON that starts with the < symbol.

For instance, we should parse anything with JSON.parse like:

JSON.parse('<...')

Also, we shouldn’t parse HTTP responses that starts with < when we’re expecting JSON.

The response text can be logged to check when the response is.

Conclusion

To fix the “SyntaxError: Unexpected token < in JSON at position 0” error when developing React apps, we should make sure that we aren’t parsing any JSON that starts with the < symbol.

Also, we shouldn’t parse HTTP responses that starts with < when we’re expecting JSON.