What the error is telling you
response.json() failed on it.On 16.10.2026 we sent a form to /api/contakt, a typo for /api/contact, on a Next.js 16.4.2 app. The server answered 404 with its HTML not-found page, and await response.json() in Chromium 152 threw:
SyntaxError: Failed to execute 'json' on 'Response': Unexpected token '<', "<!DOCTYPE "... is not valid JSON
The quoted part is the start of what came back. That makes the error more useful than it looks: it tells you what kind of reply you got.
| Error text | What the server sent, on our tests |
|---|---|
Unexpected token '<', "<!DOCTYPE "... | An HTML page: Next.js's 404 for a wrong path, GET or POST |
Unexpected token 'I', "Invalid Se"... | Next.js 16's 400 “Invalid Server Action request.” for a FormData POST to a path that does not exist |
Unexpected token 'F', "Forbidden" is not valid JSON | Mailgun's plain-text 401 (Mailgun guide) |
Unexpected end of JSON input | A 500 with an empty body |
Firefox and Safari say it differently
We ran the same replies through Firefox 142 and WebKit 26, the engine behind Safari:
- Firefox, HTML or text reply:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data. Empty reply:JSON.parse: unexpected end of data at line 1 column 1 of the JSON data. - Safari, for all three:
SyntaxError: The string did not match the expected pattern.
Neither quotes the reply, so in those browsers the Network tab is the only way to see what came back.
Why a page comes back instead of JSON
- A wrong URL. A typo, a missing
/apiprefix, or a relative URL that resolves against the current page. - The API is not deployed. On a static host the route does not exist, and the host answers with its 404 page or with
index.html(single-page apps often send every path there, with status 200). - A server error page. The route crashed and the framework answered with an HTML error page.
- A login or firewall page. A protected preview deployment or a bot check answers with its own HTML.
Parse only what is JSON
Read the body once as text, check the status and content type, and include the start of the body in your error. Then the next failure tells you the cause instead of a character.
async function readJson(response) {
const text = await response.text(); // read the body once
const type = response.headers.get("content-type") || "";
if (!type.includes("application/json")) {
throw new Error(`Expected JSON, got ${response.status} ${type}: ${text.slice(0, 80)}`);
}
return JSON.parse(text);
}
const response = await fetch("/api/contact", { method: "POST", body: new FormData(form) });
const data = await readJson(response);
if (!response.ok) showError(data.error);Formgong always answers in JSON
When a fetch posts to Formgong at https://formgong.com/submit with Accept: application/json, errors come back as JSON too: on 16.10.2026 a made-up access key got HTTP 404 with {"success":false,"code":"unknown_access_key"}, so response.json() works and the code can show the reason. See the HTML guide.
Frequently asked questions
What does Unexpected token < DOCTYPE is not valid JSON mean?
Your code called response.json() on an HTML page. The request reached a server, but the reply was a web page, usually a 404 or error page, not JSON.
How do I find out what the server returned?
Open DevTools, go to the Network tab, click the request and read its status and Response tab. Or read response.text() and log the first characters.
What is the Safari version of this error?
Safari's WebKit says SyntaxError: The string did not match the expected pattern. Firefox says JSON.parse: unexpected character at line 1 column 1 of the JSON data.
Why does it say Unexpected end of JSON input?
The reply had an empty body, often a 500 or 204. There was nothing to parse. Check the status before calling response.json().
Sources and documentation
Official references for this guide: MDN: Response.json(), MDN: SyntaxError: JSON.parse: bad parsing, MDN: Response.ok. HTML contact form, where data is stored.
Related guides
- Lovable form submissions to email and Telegram
- HTML contact form without a backend: a working example
- How to send website form submissions to Telegram
- Contact form not sending email? Check where it stops
- Managing website leads in Telegram without a CRM
- Form backend for Lovable, Bolt, v0, Cursor
- Telegram bot for a contact form: build or skip?
- GDPR form backend: 7 checks before you choose
- Lovable form not sending email? 6 fixes
- Netlify Forms not working? React and Bolt fixes
- Stop contact form spam without a CAPTCHA
- GitHub Pages contact form: a working setup
- Mailto Form in HTML: Why It Fails and What to Use
- HTML form to Google Sheets: 2 free methods
- Webflow form submission limit: what to do at 50
- Turnstile vs reCAPTCHA vs hCaptcha for forms
- Contact Form 7 and Elementor forms to Telegram
- Squarespace contact form not sending email?
- Shopify contact form: where do messages go?
- Google Form to Telegram: free Apps Script way
- Wix contact form not sending email? Fixes
- EU / GDPR Formspree alternatives compared
- HTML form action attribute explained
- How do HTML forms work? The HTTP request
- Types of Injection Attacks on Web Forms (2026)
- Indirect Prompt Injection in MCP
- MCP Rug Pull Attack: Detect Tool Changes
- Form without a backend: 7 ways that work
- Thank-you page after form submission (HTML)
- Indirect Prompt Injection Examples (2023–2026)
- Indirect Prompt Injection via Email
- What Is Tool Poisoning in MCP?
- WordPress contact form without a plugin
- Send email from frontend JavaScript
- How to Prevent Indirect Prompt Injection
- Honeypot Form Field: How to Add One That Works
- Contact Form with File Upload (HTML, No PHP)
- Angular contact form without a backend
- Send form submissions to Slack or Discord without Zapier
- Verify a form webhook signature (HMAC-SHA256)
- Contact forms that send nothing: 793 AI-built sites tested
- v0 contact form that actually sends: 3 ways
- How we tested AI-built contact forms, and 12 bugs we hit
- Cloudflare vs Netlify free plan: hosting that never pauses
- EmailJS 412 “Gmail_API: Invalid grant”: reconnect Gmail
- Resend “You can only send testing emails”: verify a domain
- Supabase Edge Function blocked by CORS policy: 3 causes
- Formspree “Form not found” and other errors: fixes
- Web3Forms errors: “Invalid access key” and 403 explained
- How to add customer reviews to your website for free
- Getform not working? “This form has been deleted” and more
- Next.js contact form not working? 6 errors, reproduced
- Webflow form not sending email? What to check, tested
- FormSubmit not working? “This form needs Activation” fix
- Contact form “TypeError: Failed to fetch”: causes and fixes
- WooCommerce product enquiry form
- Contact Form 7 vs WPForms
- Gravity Forms alternative free
- WordPress contact form block
- 535-5.7.8 Username and Password not accepted (Gmail)
- 535 5.7.3 Authentication unsuccessful: Office 365 SMTP
- Nodemailer “Missing credentials for "PLAIN"”: the fix
- Nodemailer “Greeting never received”: port 465 fix
- Nodemailer SSL “wrong version number”: the port fix
- Nodemailer “self-signed certificate in certificate chain”
- Nodemailer ECONNREFUSED 127.0.0.1:587: missing SMTP host
- SendGrid “authorization grant is invalid”: 401 fix
- Mailgun 401 Forbidden: why the API rejects your key
- “Edge Function returned a non-2xx status code”: the fix
- Next.js “Body exceeded 1 MB limit”: Server Action fix
- “TypeError: Body is unusable”: body has already been read
- Turnstile “timeout-or-duplicate” and other siteverify errors
- Turnstile vs hCaptcha vs reCAPTCHA: speed and size tested
- Judge.me reviews not showing on Shopify: how to fix it
- Judge.me review carousel not showing: how to fix it
- Yotpo reviews not showing on Shopify? Check the app embed
- Loox reviews not showing on product page: how to fix
- Shopify reviews not showing: what to check first
- How to show reviews on Shopify
- GDPR for website forms: what each type of form needs
- WooCommerce reviews not showing: how to fix it
- Stamped.io reviews not showing on Shopify: how to fix it
- Etsy reviews not showing: why and what to do
- Trustpilot widget not loading: how to fix TrustBox
- Yotpo problems in 2026: what merchants report
- Contact Form 7 “error trying to send your message” fix
- Elementor form “Your submission failed because of an error”
- Framer form not sending email or not working: what to check
- Carrd contact form not working: plans, spam and errors
- Google review link not working: what customers see and why
- tawk.to widget not showing on your website: causes and fixes
- How to add questions and answers to your product page
- “Failed to send a request to the Edge Function”: fixes
- Next.js “Failed to find Server Action”: what it means
- Brevo “unauthorized: Key not found” 401: the fix
- Amazon SES “Email address is not verified”: the fix
- Shopify contact form not working: how to fix it
- Judge.me alternative for WooCommerce after the 2025 shutdown
- Free WooCommerce review plugins compared on the free version
- WooCommerce review reminder emails without a paid plugin
- Add Voice Recording to a Website Form
- Contact Form 7 spam: how to stop it
- WPForms not sending email: how to fix it
- Contact form emails going to spam: how to fix it
- HTML form not submitting: how to fix it
- Contact form not working: how to find the fault
- Webflow form spam: how to stop it
- Website form to Notion: how to set it up
- Website form to WhatsApp: what works and what does not