Angular: Http failure during parsing for http://…: SyntaxError: Unexpected token '<' (response is not JSON)
The request succeeded (status 200) but the body could not be parsed as the expected type — usually HTML or plain text instead of JSON.
Http failure during parsing forSyntaxError: Unexpected token '<' in JSON at position 0 Http failure during parsingHttp failure during parsing for http://localhost:4200/apiHttpErrorResponse Http failure during parsingUnexpected token < in JSON Meaning
HttpClient parses responses as JSON by default. If the server returns an HTML page (proxy error, login redirect, SPA fallback) or plain text, parsing fails with Http failure during parsing. Use responseType: 'text' for text endpoints, or fix the URL so the API returns JSON.
Common causes
- The URL returns HTML (the SPA
index.htmlor an error page) - Endpoint returns plain text or an empty body with a JSON default
- Wrong
Acceptheader or response type - API returns invalid JSON (trailing comma, BOM)
- Proxy/redirect to a login page
⚡ Quick fix
- Open the URL in the browser or curl and check the body
- Set
responseType: 'text'(or 'blob') where JSON is not returned - Fix the endpoint or proxy path so it returns JSON
Detailed fix by platform
Angular
this.http.get(url, { responseType: 'text' })for text responses- Debug:
curl -i -H "Accept: application/json" https://api.example.com/x
Code examples
Plain text endpoint
this.http.get('/api/version', { responseType: 'text' }).subscribe(v => console.log(v)); // "1.4.2"How to diagnose
- Body — What does curl return?
- Type — JSON or text?
- Path — Is a proxy returning HTML?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- entity.parse.failed API Error: Malformed JSON in request body (entity.parse.failed / JSON parse error)
- exceeded maximum budget Angular build: Error: bundle initial exceeded maximum budget. Budget 1.00 MB was not met by 120.00 kB with a total of 1.12 MB
- Http failure response for (unknown url): 0 Unknown Error Angular: HttpErrorResponse — Http failure response for (unknown url): 0 Unknown Error (status 0)
Most viewed in Angular
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026