Categories
React Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *