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
Previous
Are there online tools to convert large JSON files to TypeScript interfaces?
Next
How do you stringify a JSON object with circular references in JavaScript?
Related Questions
How do you stringify a JSON object with circular references in JavaScript?
Learn how to stringify JSON objects with circular references in JavaScript. Master custom replacer functions and libraries.
How do I fix "is not valid against the requested profile" JSON schema errors?
Fix "not valid against requested profile" JSON schema errors. Learn how to validate and correct JSON schema violations.
Why is my JSON valid but still failing to parse in my application?
Learn why valid JSON fails to parse in applications. Discover encoding, environment, and parser-specific issues and solutions.
Still have questions?
Can't find the answer you're looking for? Please reach out to our support team.