Why am I getting a 'SyntaxError: Unexpected token < in JSON at position 0' when using fetch?

Responsive Ad Header

Question

Grade: Education Subject: Support
Why am I getting a 'SyntaxError: Unexpected token < in JSON at position 0' when using fetch?
Asked by:
92 Viewed 92 Answers

Answer (92)

Best Answer
(307)
This error often indicates that the server is not returning valid JSON. The '<' token at position 0 usually points to an HTML doctype or an opening HTML tag. Check the server response to see if it's sending HTML instead of JSON, and verify that the server's content-type header is set to 'application/json'.