KKitForma.

Language

EnglishEnglishTürkçeTurkishGuide unavailable in this language · open toolsDeutschGermanGuide unavailable in this language · open toolsEspañolSpanishGuide unavailable in this language · open toolsFrançaisFrenchGuide unavailable in this language · open toolsPortuguêsPortugueseGuide unavailable in this language · open toolsItalianoItalianGuide unavailable in this language · open toolsNederlandsDutchGuide unavailable in this language · open toolsPolskiPolishGuide unavailable in this language · open toolsРусскийRussianGuide unavailable in this language · open toolsУкраїнськаUkrainianGuide unavailable in this language · open toolsSvenskaSwedishGuide unavailable in this language · open toolsNorskNorwegianGuide unavailable in this language · open toolsDanskDanishGuide unavailable in this language · open toolsSuomiFinnishGuide unavailable in this language · open toolsČeštinaCzechGuide unavailable in this language · open toolsRomânăRomanianGuide unavailable in this language · open toolsΕλληνικάGreekGuide unavailable in this language · open toolsالعربيةArabicGuide unavailable in this language · open toolsעבריתHebrewGuide unavailable in this language · open toolsفارسیPersianGuide unavailable in this language · open toolsاردوUrduGuide unavailable in this language · open toolsहिन्दीHindiGuide unavailable in this language · open toolsবাংলাBengaliGuide unavailable in this language · open toolsதமிழ்TamilGuide unavailable in this language · open toolsతెలుగుTeluguGuide unavailable in this language · open toolsमराठीMarathiGuide unavailable in this language · open toolsગુજરાતીGujaratiGuide unavailable in this language · open tools简体中文Chinese SimplifiedGuide unavailable in this language · open tools繁體中文Chinese TraditionalGuide unavailable in this language · open tools日本語JapaneseGuide unavailable in this language · open tools한국어KoreanGuide unavailable in this language · open toolsTiếng ViệtVietnameseGuide unavailable in this language · open toolsไทยThaiGuide unavailable in this language · open toolsBahasa IndonesiaIndonesianGuide unavailable in this language · open toolsBahasa MelayuMalayGuide unavailable in this language · open toolsFilipinoFilipinoGuide unavailable in this language · open toolsKiswahiliSwahiliGuide unavailable in this language · open toolsAfrikaansAfrikaansGuide unavailable in this language · open toolsMagyarHungarianGuide unavailable in this language · open toolsБългарскиBulgarianGuide unavailable in this language · open toolsHrvatskiCroatianGuide unavailable in this language · open toolsSrpskiSerbianGuide unavailable in this language · open toolsSlovenčinaSlovakGuide unavailable in this language · open toolsSlovenščinaSlovenianGuide unavailable in this language · open toolsLietuviųLithuanianGuide unavailable in this language · open toolsLatviešuLatvianGuide unavailable in this language · open toolsEestiEstonianGuide unavailable in this language · open toolsCatalàCatalanGuide unavailable in this language · open toolsEuskaraBasqueGuide unavailable in this language · open tools
← Questions & answers

KITFORMA · EDITORIAL ANSWER

Why does a successful DELETE request fail with Unexpected end of JSON input?

KitForma editorial guide. Handle a bodyless 204 response before parsing JSON, while keeping HTTP failures and malformed promised JSON visible.

HTML, CSS & accessibility →

Step-by-step answer

A 204 response has no JSON body. Treat it according to the endpoint contract before calling json(). This example uses local Response objects, so it performs no DELETE request. Runnable example:
javascript
async function readDeleteResponse(response) {
  if (!response.ok) throw new Error("HTTP " + response.status);
  if (response.status === 204) return null;
  return response.json();
}
console.log(await readDeleteResponse(new Response(null, { status: 204 })));
const result = await readDeleteResponse(new Response('{"deleted":true}'));
console.log(result.deleted);
try {
  await readDeleteResponse(new Response(""));
} catch (error) {
  console.log(error.name);
}
Expected result:
text
null
true
SyntaxError
Why it works: An HTTP success and a successful JSON parse are separate checks. The empty 200 fixture still throws because this sample contract promises JSON for non-204 successes. Catching every parse failure and returning null would hide a broken server response. Scope and checks: Run as a Node.js 24 module or in a modern browser console with top-level await. In application code, pass the actual fetch response to the helper. If an endpoint legitimately returns another format or another bodyless status, specify that contract rather than guessing from an empty string. Related tools and guides: Inspect a nonempty JSON response sample: https://kitforma.com/en/json-formatter/ Reading a response body once: https://kitforma.com/en/community/questions/7aa10000-0000-4000-8000-000000003830/ Primary sources (reviewed 2026-10-08): WHATWG Fetch — null body statuses and body parsing: https://fetch.spec.whatwg.org/#body-mixin

Sources and verification

Sources checked:

This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.

Discussion and community answers

Loading community…
KitForma

What would you like to do?