• Thread Author
A JSON parse error is a common, often confounding fault that occurs when software attempts to read text that it expects to be valid JSON but finds malformed, encoded, or unexpected content instead — the symptom you see is usually a JavaScript SyntaxError such as “Unexpected token … in JSON at position …,” and the cure ranges from a simple syntax fix to checking encodings, headers, or cached responses. This article condenses the practical quick fixes published in the Windows Report how‑to, verifies the technical causes against authoritative developer guidance, and lays out a robust, safe‑for‑production troubleshooting workflow so you can fix JSON parse errors quickly and avoid repeat occurrences. (developer.mozilla.org)

Blue-lit desk with two monitors displaying code and sticky-note reminders.Background / Overview​

JSON (JavaScript Object Notation) is the lingua franca for modern APIs, browser responses, configuration files, and many inter‑process formats. A JSON parse error appears when a parser (for example, JavaScript’s JSON.parse or a language library) receives bytes that do not conform to valid JSON grammar. The typical outcomes you’ll encounter are:
  • Browser or runtime exceptions such as “Unexpected token < in JSON at position 0” or “Unexpected token } in JSON at position X.”
  • Applications that refuse to start because they can’t load a configuration file.
  • Services failing to decode API payloads and returning 4xx/5xx errors.
The Windows Report quick‑fix guide condenses the usual user steps — validate, clear cache, update the client, and prevent future mistakes — into a practical workflow that works for editors and non‑technical users alike.

What a JSON parse error actually means​

The parser’s perspective​

When JSON.parse (or an equivalent parser) runs, it performs two things: tokenization and grammar validation. If the input contains an illegal character, mismatched punctuation, or unexpected encoding bytes, the parser will throw a SyntaxError and abort. MDN explains that “unexpected token” errors occur when the parser encounters a token it does not expect at that position. (developer.mozilla.org)

Common real‑world causes (short list)​

  • Invalid syntax — missing quotes, missing or extra commas, trailing commas, unquoted keys.
  • Wrong content returned — the server returned HTML or plain text instead of JSON (commonly shows as “Unexpected token < …”). (daveceddia.com)
  • Encoding problems — Byte Order Mark (BOM) or non‑UTF‑8 characters at the start of the stream. (stackoverflow.com)
  • Corrupted file or copy/paste errors — invisible control characters, truncated downloads, or stray characters from editors. (rishandigital.com)
  • Outdated or incompatible software — older apps or viewers with incomplete JSON support can choke on newer JSON constructs or encodings.

Quick, reliable fixes (practical workflow)​

1. Validate the JSON file first (the single most effective step)​

Open the file in a capable text editor (Visual Studio Code, Notepad++), or paste the text into an online JSON linter / validator. Editors like VS Code highlight syntax problems immediately and show the Problems pane for quick navigation. Use validation to find misplaced commas, missing quotes, extra trailing commas, or structural mismatches, then save and re‑test. This is the top recommendation in the Windows Report guide.
Why validation helps: validators show the exact error position and expected token, making the repair deterministic rather than guesswork.
Practical tools:
  • Visual Studio Code (built‑in JSON validation)
  • Notepad++ (with JSON plugins)
  • JSONLint / online formatters (paste & validate quickly)

2. Fix the obvious syntax errors​

After validation, correct the errors the tool points to:
  • Ensure keys and string values use double quotes.
  • Remove trailing commas (JSON does not allow them).
  • Balance braces and brackets ({}, []).
  • Replace JavaScript expressions (undefined, functions) with JSON‑legal values (null, primitives, arrays, objects). (rishandigital.com)

3. Check for encoding or BOM issues​

If the syntax looks correct but parsing still fails at position 0, the file may contain an invisible BOM (a Unicode marker) or be saved in the wrong encoding. Strip a BOM and re‑save the file as UTF‑8 without BOM. Node and browser parsers choke if the very first code point is an unexpected BOM byte; this is a common StackOverflow‑documented cause. (stackoverflow.com)
Step to test:
  • Open the file in an editor that shows encoding (VS Code: status bar → select encoding).
  • Re‑save as UTF‑8 (without BOM).
  • Trim any leading whitespace or control characters.

4. Make sure the server actually returned JSON (browser/API cases)​

If you’re parsing a network response (fetch, XHR, REST client), use your browser’s DevTools (Network tab) to inspect the raw response body and Content-Type header. Many “Unexpected token <” errors indicate that the server returned HTML (an error page, redirect, or login page) instead of JSON. Confirm:
  • Response Content‑Type: application/json (or appropriate).
  • Response body begins with { or [ (not < or other text). (daveceddia.com)
If you find HTML, the fix is server‑side (correct the endpoint, handle authentication, or return JSON). If you control the server, ensure it does not return HTML error pages for API endpoints; return JSON error objects instead.

5. Clear browser or app cache / restart the client​

Cached assets or stale responses can cause parsers to see outdated or corrupted data. Clear the browser cache and cookies or clear the application cache if the problem is seen in a desktop/mobile client. Restart the application or reload the page. This simple step often resolves transient parse errors where a partially cached file is malformed. The Windows Report guide lists clearing cache as a quick remedial step.
Sequence for browsers:
  • Hard refresh first (Ctrl+F5 / Cmd+Shift+R).
  • Clear specific site data or browser cache (Settings → Privacy → Clear browsing data).
  • Retry in a private/incognito window to rule out extensions.

6. Update or reinstall the software​

If the file is valid and the server response is correct but parsing still fails, check for updates to the application or the library doing the parsing. Older clients may have subtle parsing differences or bugs; updating to the latest stable release resolves many compatibility issues. When updates fail to help, a reinstall can clear corrupted runtime components.

Step‑by‑step example: fixing an “Unexpected token <” in a web app​

  • Open DevTools → Network → Make the request again.
  • Inspect the failing request’s Response tab; confirm the payload is HTML (looks like <html>).
  • Check the response status code (401, 403, 500 are common reasons for HTML error pages).
  • If it’s a 401/403, verify the API authentication token — you may be receiving a login or error page instead of JSON.
  • If it’s 500, check the server logs and return a JSON error body rather than an HTML error page.
  • After server fix, validate the response Content‑Type header is application/json, then retry fetch(). (daveceddia.com)

Technical deep dive: why specific mistakes trip parsers​

Trailing commas and unquoted keys​

JSON is stricter than JavaScript object literals. Trailing commas and unquoted keys are invalid in JSON and will raise SyntaxError with tokens pointing to the offending character. Validators flag these instantly. (rishandigital.com)

BOM and invisible characters​

Files produced by some editors or copy/paste operations can contain a BOM (0xFEFF) at the beginning. Parsers that do not pre‑strip it treat it as an unexpected token. The standard remedy is to trim the file and save it as UTF‑8 without BOM. StackOverflow examples demonstrate this exact failure mode and the practical fix. (stackoverflow.com)

Wrong Content-Type or HTML payloads​

APIs often return human‑readable error pages (HTML) for faults. A client treating every response as JSON will attempt JSON.parse and fail immediately; the token “<” (start of HTML) is a dead giveaway. Debug by inspecting network traffic before making changes to client code. (daveceddia.com)

Prevention: how to avoid future JSON parse errors​

  • Always validate before deploy — Add JSON linting to CI pipelines so configuration files and API responses are validated automatically.
  • Use strict serialization on the server — Ensure servers explicitly set Content‑Type: application/json for JSON responses and return JSON error objects with consistent shapes.
  • Avoid manual edits for production JSON — When possible, generate JSON programmatically instead of hand‑editing to eliminate syntax errors.
  • Add robust error handling — Wrap JSON.parse in try/catch on the client and provide fallbacks or clear error messages that include the raw snippet for debugging.
  • Use versioned API contracts — When APIs change, version the endpoint and document breaking changes so clients are not surprised by new structures.
  • Keep tooling up to date — Editors, linters, runtimes, and libraries get bug and behavior fixes; keep them current.

Advanced troubleshooting checklist (for developers)​

  • Confirm file encoding is UTF‑8 and there’s no BOM.
  • Trim leading/trailing whitespace and control characters programmatically before parsing.
  • Log the raw response (or file contents) to persistent logs so you can search for systemic truncation or corruption.
  • Add Content‑Type validation on the client: if response.headers.get('content-type') does not include 'application/json', do not attempt JSON.parse blindly.
  • Add schema validation (JSON Schema) to detect structural regressions early.
  • If the payload is large, verify streaming vs full‑buffer parsing limits; use streaming parsers for very large JSONs to avoid memory issues.

Where Windows Report’s guidance helps — and where to watch out​

Strengths:
  • The Windows Report article gives a clear, user‑friendly triage: validate, clear cache, update, and prevent — a concise workflow that non‑developers can implement immediately.
  • The article highlights practical editors (Notepad++, VS Code) and suggests using online linters for quick checks, which speeds up resolution for the majority of cases.
  • For browser issues, the guidance to clear browser/app cache and to check for Firefox viewer quirks is pragmatic; clearing cache often fixes transient parsing/display problems.
Risks and limitations:
  • The Windows Report guide is practical but high level — it intentionally keeps server‑side remediation brief. For API developers, deeper fixes (ensuring correct Content‑Type headers, returning JSON for error responses, server logging) require developer intervention not covered in depth.
  • Some causes are subtle (BOM, encoding, invisible bytes) and require specific file‑level tools or hex viewers to diagnose; novices may misinterpret symptoms and attempt unnecessary reinstalls. StackOverflow and MDN explain these nuances and provide the low‑level fixes you may need. (stackoverflow.com, developer.mozilla.org)
  • When the JSON error is caused by a server delivering HTML (for example, because of authentication redirects), fixing the client alone is insufficient; the server must be corrected. Windows Report correctly recommends caching and client updates but readers must be alerted that a server fix is often necessary for network requests.
Cautionary note: if you encounter an error message that references specific internals (for example, platform or vendor faults) which you can’t reproduce locally, treat vendor claims with caution until validated. Log the raw response and inspect it — never rely on paraphrased diagnostics alone.

Quick reference: short fixes you can try in under 10 minutes​

  • Open the JSON file in VS Code and check the Problems panel — fix highlighted issues.
  • Paste JSON into an online linter (JSONLint) — correct the flagged tokens.
  • If parsing fails on position 0, re‑save the file as UTF‑8 without BOM and trim whitespace. (stackoverflow.com)
  • For web apps: open DevTools → Network → check response body and Content‑Type. If it’s HTML, fix server or auth flow. (daveceddia.com)
  • Clear browser or app cache and try again; test in incognito mode to rule out extensions.

When to escalate​

  • If the JSON file is part of a vendor package or OS component and repeated validation shows it is well‑formed, escalate to the vendor — do not attempt to force‑fix critical system files without vendor guidance.
  • If the problem is reproducible across many clients and DevTools shows a server‑side error (500/502/403), escalate to the backend team with request IDs and raw payloads attached. (daveceddia.com)
  • If disk errors, repeated corruption, or partial downloads surface, check disk health and network infrastructure as these can intermittently corrupt files. Use CHKDSK/DISM/SFC when file corruption spans multiple system files.

Final checklist for a definitive fix​

  • Validate JSON syntax with an editor or linter.
  • Confirm encoding = UTF‑8 without BOM. (stackoverflow.com)
  • Inspect server responses for correct Content‑Type and JSON body. (daveceddia.com)
  • Clear caches and test in fresh sessions.
  • Add schema validation and CI linting to prevent regressions.
  • If unresolved, gather raw payloads and escalate with concrete evidence (request IDs, logs).

JSON parse errors are rarely mysterious once you know the likely failure modes: bad syntax, the wrong content type, encoding artifacts, or caching. The practical workflow — validate, fix syntax, inspect encoding, check responses, clear cache, and keep software up to date — resolves the large majority of cases quickly. The Windows Report primer is a reliable quick checklist for everyday users, while the deeper technical verification steps here (supported by MDN and community diagnostics) give developers the precise tests and fixes needed to make the problem go away for good. (developer.mozilla.org, daveceddia.com)


Source: Windows Report JSON Parse Error Fix: Simple Steps That Work
 

Back
Top