JSON Errors

Why am I getting "Uncaught SyntaxError: Unexpected token in JSON at position 0"?

This error occurs when JSON.parse() receives invalid JSON, often HTML error pages instead of JSON. Common causes: API returned 404/500 error page as HTML instead of JSON response. CORS issues causing browser to block response, leaving empty string. Server returned plain text without JSON formatting. Response starts with HTML tags like <html>. Network error interrupted response. Response has BOM (Byte Order Mark) at start. API endpoint incorrect returning default page. Authentication failed resulting in login page HTML. Always check response.ok before parsing: if (!response.ok) throw error. Log response.text() to see actual content received. Verify API endpoint URL is correct. Check Network tab in DevTools for actual response. Enable CORS headers on server. Handle errors before JSON parsing. Validate API responses return proper JSON content-type headers. Test API endpoints with our JSON Validator at jsonconsole.com/json-editor to ensure valid JSON. Add error handling wrapping JSON.parse() in try-catch. Check for empty responses before parsing. This error almost always indicates receiving non-JSON when expecting JSON.
Last updated: December 23, 2025

Still have questions?

Can't find the answer you're looking for? Please reach out to our support team.