[{"data":1,"prerenderedAt":1395},["ShallowReactive",2],{"blog-post-en-json-parse-error-debug":3,"surround-\u002Fen\u002Fblog\u002Fjson-parse-error-debug":1388},{"id":4,"title":5,"author":6,"body":7,"category":1362,"date":1363,"description":1364,"draft":1365,"extension":1366,"h1":1367,"image":1368,"lastmod":1369,"locales":1370,"meta":1373,"navigation":1374,"path":1375,"promo":1376,"seo":1380,"stem":1381,"tags":1382,"__hash__":1387},"blog\u002Fen\u002Fblog\u002Fjson-parse-error-debug.md","JSON Parse Failed: 10 Common API Errors and How to Debug Them","JSON Toolbox Team",{"type":8,"value":9,"toc":1291},"minimark",[10,28,40,45,48,77,84,87,90,94,99,114,120,124,139,143,193,197,226,228,234,237,254,258,275,278,294,297,319,321,325,328,353,357,396,399,412,415,423,425,429,432,455,458,470,473,513,516,538,540,544,547,550,575,578,589,592,606,609,633,635,639,642,654,657,665,668,676,679,694,696,700,703,718,721,726,729,759,762,770,772,776,779,805,808,816,819,827,830,868,870,874,877,893,896,904,907,915,918,930,932,938,941,952,955,963,966,991,994,1030,1038,1040,1044,1047,1125,1127,1131,1240,1242,1246,1257,1265,1269],[11,12,13,14,18,19,22,23,27],"p",{},"In frontend and backend development, \"JSON parse failed\" is one of the most common errors: your code expects a JSON response, but ",[15,16,17],"code",{},"JSON.parse"," throws an exception and the console fills with red errors.",[20,21],"br",{},"\nThis article breaks down ",[24,25,26],"strong",{},"10 typical JSON parsing errors"," from real-world debugging scenarios, and provides actionable troubleshooting steps and prevention tips to help you quickly locate and fix the root cause.",[29,30,31],"blockquote",{},[11,32,33,34,39],{},"If you have a \"parse failed\" JSON sample on hand, paste it into the ",[35,36,38],"a",{"href":37},"\u002Ftools\u002Fformat\u002Fjson-editor","JSON Editor"," to automatically check syntax and highlight the exact error position.",[41,42,44],"h2",{"id":43},"overview-of-typical-error-messages","Overview of Typical Error Messages",[11,46,47],{},"Across different environments and scenarios, you might see errors like:",[49,50,51,57,62,67,72],"ul",{},[52,53,54],"li",{},[15,55,56],{},"SyntaxError: Unexpected token ':' in JSON at position 3",[52,58,59],{},[15,60,61],{},"SyntaxError: Unexpected token '\u003C' in JSON at position 0",[52,63,64],{},[15,65,66],{},"SyntaxError: Unexpected token 'u' in JSON at position 20",[52,68,69],{},[15,70,71],{},"SyntaxError: Unexpected token '\u002F' in JSON at position 2",[52,73,74],{},[15,75,76],{},"JSONParseError: Unexpected end of JSON input",[11,78,79,80,83],{},"These all mean: ",[24,81,82],{},"the input is not valid JSON",", but the underlying reasons can be very different: format errors, HTML error pages, encoding issues, truncated responses, and more.",[11,85,86],{},"Below, we break them down by scenario.",[88,89],"hr",{},[41,91,93],{"id":92},"scenario-1-backend-returns-an-html-error-page-500404","Scenario 1: Backend Returns an HTML Error Page (500\u002F404)",[95,96,98],"h3",{"id":97},"symptoms","Symptoms",[49,100,101,104,107],{},[52,102,103],{},"Your frontend calls an API expecting JSON.",[52,105,106],{},"The actual status code is 500\u002F404\u002F503, and the body is an HTML error page.",[52,108,109,110,113],{},"The frontend still calls ",[15,111,112],{},"JSON.parse(responseText)"," and fails with:",[29,115,116],{},[11,117,118],{},[15,119,61],{},[95,121,123],{"id":122},"cause","Cause",[11,125,126,127,130,131,134,135,138],{},"HTML usually starts with ",[15,128,129],{},"\u003C!DOCTYPE html>"," or ",[15,132,133],{},"\u003Chtml>",", so the first character is ",[15,136,137],{},"\u003C",", which is not valid JSON.",[95,140,142],{"id":141},"debugging-steps","Debugging Steps",[144,145,146,149,156,186],"ol",{},[52,147,148],{},"Open the browser's Network panel and find the request.",[52,150,151,152,155],{},"Check the ",[24,153,154],{},"Status"," code: is it 2xx?",[52,157,158,159,162,163,166,167],{},"Check ",[15,160,161],{},"Content-Type"," in ",[24,164,165],{},"Response Headers",":\n",[49,168,169,176],{},[52,170,171,172,175],{},"Is it ",[15,173,174],{},"application\u002Fjson","?",[52,177,178,179,182,183,175],{},"Or ",[15,180,181],{},"text\u002Fhtml"," \u002F ",[15,184,185],{},"text\u002Fplain",[52,187,188,189,192],{},"Inspect the ",[24,190,191],{},"Response Body",": is it an HTML error page?",[95,194,196],{"id":195},"solutions","Solutions",[49,198,199,219],{},[52,200,201,202,204,205],{},"Before calling ",[15,203,17],{}," on the frontend:\n",[49,206,207,210],{},[52,208,209],{},"Check that the status code is 2xx;",[52,211,212,213,215,216,218],{},"Check that ",[15,214,161],{}," includes ",[15,217,174],{},".",[52,220,221,222,225],{},"For non-2xx responses, prioritize showing error information (e.g., ",[15,223,224],{},"error.message",") instead of trying to parse JSON.",[88,227],{},[41,229,231,232],{"id":230},"scenario-2-content-type-is-not-applicationjson","Scenario 2: Content-Type Is Not ",[15,233,174],{},[95,235,98],{"id":236},"symptoms-1",[49,238,239,249],{},[52,240,241,242,244,245,130,247,218],{},"The response body \"looks like JSON\", but ",[15,243,161],{}," is ",[15,246,181],{},[15,248,185],{},[52,250,251,252,218],{},"Some frameworks\u002Fmiddleware refuse to auto-parse, or your code hesitates to safely call ",[15,253,17],{},[95,255,257],{"id":256},"causes","Causes",[49,259,260,266,269],{},[52,261,262,263,265],{},"Backend framework configuration (e.g., defaulting to ",[15,264,181],{},").",[52,267,268],{},"Reverse proxy\u002Fgateway modifying response headers.",[52,270,271,272,274],{},"Error-handling middleware returning ",[15,273,181],{}," for all errors.",[95,276,142],{"id":277},"debugging-steps-1",[144,279,280,285,288],{},[52,281,158,282,284],{},[15,283,161],{}," in the Network panel.",[52,286,287],{},"Compare response headers between working and failing endpoints.",[52,289,290,291,293],{},"Inspect backend code\u002Fconfiguration for explicit ",[15,292,161],{}," settings.",[95,295,196],{"id":296},"solutions-1",[49,298,299,310],{},[52,300,301,302,305,306,309],{},"On the backend, consistently return ",[15,303,304],{},"Content-Type: application\u002Fjson"," and encode the body as UTF-8. Many frameworks also emit ",[15,307,308],{},"application\u002Fjson; charset=utf-8","; the important part is that the response body is actually valid JSON and uses a consistent UTF-8 encoding.",[52,311,312,313,315,316,318],{},"On the frontend, be cautious when parsing responses whose ",[15,314,161],{}," is not ",[15,317,174],{},", or at least log them first.",[88,320],{},[41,322,324],{"id":323},"scenario-3-trailing-commas-single-quotes-comments-fake-json","Scenario 3: Trailing Commas \u002F Single Quotes \u002F Comments (\"Fake JSON\")",[95,326,98],{"id":327},"symptoms-2",[49,329,330,333],{},[52,331,332],{},"You copy \"JSON-like\" content from logs, docs, or chat tools.",[52,334,335,336],{},"Parsing it in code or tools fails with:\n",[49,337,338,343,348],{},[52,339,340],{},[15,341,342],{},"Unexpected token ','",[52,344,345],{},[15,346,347],{},"Unexpected token ':'",[52,349,350],{},[15,351,352],{},"Unexpected token '\u002F'",[95,354,356],{"id":355},"common-error-patterns","Common Error Patterns",[144,358,359,374,385],{},[52,360,361,364],{},[24,362,363],{},"Trailing commas",[365,366,372],"pre",{"className":367,"code":369,"language":370,"meta":371},[368],"language-json","{\n  \"name\": \"Alice\",\n  \"age\": 30,\n}\n","json","",[15,373,369],{"__ignoreMap":371},[52,375,376,379],{},[24,377,378],{},"Single quotes",[365,380,383],{"className":381,"code":382,"language":370,"meta":371},[368],"{\n  'name': 'Alice'\n}\n",[15,384,382],{"__ignoreMap":371},[52,386,387,390],{},[24,388,389],{},"Comments in JSON",[365,391,394],{"className":392,"code":393,"language":370,"meta":371},[368],"{\n  \u002F\u002F user info\n  \"name\": \"Alice\"\n}\n",[15,395,393],{"__ignoreMap":371},[95,397,142],{"id":398},"debugging-steps-2",[144,400,401,406,409],{},[52,402,403,404,218],{},"Paste the raw response\u002Ftext into the ",[35,405,38],{"href":37},[52,407,408],{},"Let the tool auto-format and highlight error positions.",[52,410,411],{},"Fix according to the hints: remove trailing commas, switch to double quotes, delete comments.",[95,413,196],{"id":414},"solutions-2",[49,416,417,420],{},[52,418,419],{},"Always run \"JSON from docs\u002Flogs\" through a validator first.",[52,421,422],{},"If you need \"config with comments\" in backend logs, use JSONC or YAML and clearly label it as \"non-standard JSON\".",[88,424],{},[41,426,428],{"id":427},"scenario-4-backend-returns-double-serialized-json-strings","Scenario 4: Backend Returns \"Double-Serialized\" JSON Strings",[95,430,98],{"id":431},"symptoms-3",[49,433,434,443,452],{},[52,435,436,437],{},"The response body is a string that contains JSON as text, e.g.:\n",[365,438,441],{"className":439,"code":440,"language":370,"meta":371},[368],"\"{\\\"key\\\":\\\"value\\\"}\"\n",[15,442,440],{"__ignoreMap":371},[52,444,445,446,448,449,451],{},"The frontend calls ",[15,447,17],{}," once and gets a string, not an object; only a second ",[15,450,17],{}," yields the object.",[52,453,454],{},"If your code assumes \"one parse gives an object\", it breaks.",[95,456,257],{"id":457},"causes-1",[49,459,460,467],{},[52,461,462,463,466],{},"The backend calls ",[15,464,465],{},"JSON.stringify"," on data that is already a JSON string.",[52,468,469],{},"Or an extra layer of wrapping happens in logs\u002Fmessage queues.",[95,471,142],{"id":472},"debugging-steps-3",[144,474,475,493],{},[52,476,477,478],{},"Inspect the raw response in the Network panel:\n",[49,479,480,486],{},[52,481,482,483,175],{},"Does it start and end with ",[15,484,485],{},"\"",[52,487,488,489,492],{},"Does it contain many ",[15,490,491],{},"\\\""," inside?",[52,494,495,496,504],{},"In the console:\n",[365,497,502],{"className":498,"code":500,"language":501,"meta":371},[499],"language-js","const once = JSON.parse(text);\nconsole.log(typeof once, once);\n","js",[15,503,500],{"__ignoreMap":371},[49,505,506],{},[52,507,508,509,512],{},"If ",[15,510,511],{},"typeof once === 'string'",", it's double-serialized.",[95,514,196],{"id":515},"solutions-3",[49,517,518,523],{},[52,519,520,521,466],{},"On the backend, avoid calling ",[15,522,465],{},[52,524,525,526,528,529,537],{},"If you must support such an interface on the frontend, parse the outer layer first and explicitly verify the result is a string before parsing again. Do not blindly call ",[15,527,17],{}," twice on every response — fix the API contract whenever possible:\n",[365,530,535],{"className":531,"code":533,"language":534,"meta":371},[532],"language-ts","export function parsePossiblyDoubleEncodedJson(text: string): unknown {\n  const first = JSON.parse(text)\n  if (typeof first !== 'string') {\n    return first\n  }\n  return JSON.parse(first)\n}\n","ts",[15,536,533],{"__ignoreMap":371},"\nUse this only when your API contract explicitly documents double encoding. Otherwise, treat it as a backend contract bug.",[88,539],{},[41,541,543],{"id":542},"scenario-5-large-json-causing-timeouts-memory-issues","Scenario 5: Large JSON Causing Timeouts \u002F Memory Issues",[11,545,546],{},"A large payload is often valid JSON. The failure is usually a performance, memory, or transport problem — not a JSON syntax error.",[95,548,98],{"id":549},"symptoms-4",[49,551,552,555],{},[52,553,554],{},"The API returns a very large JSON (several MB or more).",[52,556,557,558,166,560],{},"When the frontend calls ",[15,559,17],{},[49,561,562,565],{},[52,563,564],{},"The page freezes or even crashes;",[52,566,567,568,182,571,574],{},"Or you get ",[15,569,570],{},"Out of memory",[15,572,573],{},"Invalid argument"," errors in some environments.",[95,576,257],{"id":577},"causes-2",[49,579,580,583],{},[52,581,582],{},"Parsing huge JSON in one go puts heavy pressure on the main thread and memory.",[52,584,585,586,588],{},"Some environments (old browsers, low-end devices) have limits on single ",[15,587,17],{}," calls.",[95,590,142],{"id":591},"debugging-steps-4",[144,593,594,603],{},[52,595,596,597,182,600,265],{},"Check the response size in the Network panel (",[15,598,599],{},"Size",[15,601,602],{},"Transferred",[52,604,605],{},"Try opening the JSON file locally in an editor to see if it's similarly slow.",[95,607,196],{"id":608},"solutions-4",[49,610,611,622],{},[52,612,613,614],{},"On the backend:\n",[49,615,616,619],{},[52,617,618],{},"Use pagination or cursor-based pagination for large lists;",[52,620,621],{},"Return only necessary fields to reduce payload size.",[52,623,624,625],{},"On the frontend:\n",[49,626,627,630],{},[52,628,629],{},"Use lazy loading \u002F virtual lists for large datasets;",[52,631,632],{},"Where possible, use streaming parsing (e.g., JSON stream libraries in Node.js).",[88,634],{},[41,636,638],{"id":637},"scenario-6-encoding-issues-non-utf-8-bom","Scenario 6: Encoding Issues (Non-UTF-8, BOM)",[95,640,98],{"id":641},"symptoms-5",[49,643,644,647],{},[52,645,646],{},"The response fails to parse in some environments with vague errors.",[52,648,649,650,653],{},"Opening the text in an editor reveals a BOM (",[15,651,652],{},"EF BB BF",") or non-UTF-8 encoding.",[95,655,257],{"id":656},"causes-3",[49,658,659,662],{},[52,660,661],{},"Some backends\u002Fproxies output UTF-8 with BOM or other encodings.",[52,663,664],{},"For JSON exchanged between systems, UTF-8 is the required interoperable encoding. Producers must not add a byte order mark (BOM); parsers may choose whether to ignore one, so BOM-prefixed JSON can fail in strict parsers.",[95,666,142],{"id":667},"debugging-steps-5",[144,669,670,673],{},[52,671,672],{},"Save the response as a file and open it in an editor that shows encoding (e.g., VS Code, Notepad++).",[52,674,675],{},"Check for a BOM or non-UTF-8 encoding.",[95,677,196],{"id":678},"solutions-5",[49,680,681,684,687],{},[52,682,683],{},"Ensure the backend outputs JSON as UTF-8 without BOM.",[52,685,686],{},"Configure gateways\u002Fproxies not to add BOM or change encoding.",[52,688,689,690,693],{},"In browser Fetch scenarios, the decoding chain handles some BOM cases, but the real issue may be: the server outputting non-UTF-8, the file content entering JavaScript string as ",[15,691,692],{},"U+FEFF",", proxy\u002Ftranscoding corruption, unescaped control characters in JSON strings, or incorrect text decoding. Don't attribute all \"vague parse errors\" to BOM.",[88,695],{},[41,697,699],{"id":698},"scenario-7-truncated-json-network-interruption-timeout","Scenario 7: Truncated JSON (Network Interruption \u002F Timeout)",[95,701,98],{"id":702},"symptoms-6",[49,704,705,708],{},[52,706,707],{},"The response is cut off during transmission.",[52,709,710,711],{},"Errors like:\n",[29,712,713],{},[11,714,715],{},[15,716,717],{},"SyntaxError: Unexpected end of JSON input",[95,719,257],{"id":720},"causes-4",[49,722,723],{},[52,724,725],{},"Unstable network, timeouts, or proxy interruptions truncate the JSON.",[95,727,142],{"id":728},"debugging-steps-6",[144,730,731,750],{},[52,732,733,734],{},"Check the request status in the Network panel:\n",[49,735,736],{},[52,737,738,739,742,743,742,746,749],{},"Does it show ",[15,740,741],{},"(failed)",", ",[15,744,745],{},"timeout",[15,747,748],{},"aborted",", etc.?",[52,751,752,753,130,756,265],{},"Inspect whether the response content is clearly truncated (e.g., last character is not ",[15,754,755],{},"}",[15,757,758],{},"]",[95,760,196],{"id":761},"solutions-6",[49,763,764,767],{},[52,765,766],{},"Add retry logic on the frontend, especially for mobile\u002Funstable networks.",[52,768,769],{},"Optimize timeout and retry settings on the backend\u002Fops side.",[88,771],{},[41,773,775],{"id":774},"scenario-8-extra-text-mixed-in-prefixsuffix-garbage","Scenario 8: Extra Text Mixed In (Prefix\u002FSuffix Garbage)",[95,777,98],{"id":778},"symptoms-7",[49,780,781,799],{},[52,782,783,784,792,793],{},"The response has extra text before or after the JSON, e.g.:\n",[365,785,790],{"className":786,"code":788,"language":789,"meta":371},[787],"language-text","Data: {\"key\":\"value\"}\n","text",[15,791,788],{"__ignoreMap":371},"\nor\n",[365,794,797],{"className":795,"code":796,"language":789,"meta":371},[787],"{\"key\":\"value\"}---END---\n",[15,798,796],{"__ignoreMap":371},[52,800,801,802,804],{},"Calling ",[15,803,17],{}," on the entire string fails.",[95,806,257],{"id":807},"causes-5",[49,809,810,813],{},[52,811,812],{},"Some legacy systems\u002Fdebug logic append extra text to responses.",[52,814,815],{},"Logs\u002Fproxies add prefixes\u002Fsuffixes.",[95,817,142],{"id":818},"debugging-steps-7",[144,820,821,824],{},[52,822,823],{},"Inspect the full response text in the Network panel.",[52,825,826],{},"Confirm whether there are extra characters before\u002Fafter the JSON.",[95,828,196],{"id":829},"solutions-7",[49,831,832,835,845],{},[52,833,834],{},"Fix at the source if possible: ensure responses are pure JSON.",[52,836,837,840,841,844],{},[24,838,839],{},"Do not use a regex to extract arbitrary JSON from a mixed response in production."," JSON is nested and strings can contain braces, so a simple regular expression cannot reliably identify the intended JSON value. Problems include: top-level arrays ",[15,842,843],{},"[]",", braces inside string fields, multiple JSON fragments, greedy matching, and masking of protocol-layer bugs.",[52,846,847,848],{},"Reliable alternatives:\n",[144,849,850,853,856,859,865],{},[52,851,852],{},"Fix the API so the response body is always pure JSON.",[52,854,855],{},"Design separate endpoints for different content types.",[52,857,858],{},"If the protocol uses a known wrapper format (SSE, NDJSON, JSONP, specific log format), use the corresponding parser.",[52,860,861,862,864],{},"For ad-hoc debugging, copy the raw content into the ",[35,863,38],{"href":37}," and manually identify the JSON boundaries.",[52,866,867],{},"Log limited, sanitized response fragments in code — don't guess JSON boundaries.",[88,869],{},[41,871,873],{"id":872},"scenario-9-backend-returns-half-json-half-text-mixed-content","Scenario 9: Backend Returns \"Half JSON, Half Text\" Mixed Content",[95,875,98],{"id":876},"symptoms-8",[49,878,879,888],{},[52,880,881,882],{},"The first part of the response is JSON, the rest is plain text or HTML, e.g.:\n",[365,883,886],{"className":884,"code":885,"language":789,"meta":371},[787],"{\"success\":true}\n\u003Cscript>...\u003C\u002Fscript>\n",[15,887,885],{"__ignoreMap":371},[52,889,890,892],{},[15,891,17],{}," fails when it encounters the non-JSON part.",[95,894,257],{"id":895},"causes-6",[49,897,898,901],{},[52,899,900],{},"Error-handling logic outputs HTML\u002Fscripts after writing JSON.",[52,902,903],{},"Some frameworks append debug info on exceptions.",[95,905,142],{"id":906},"debugging-steps-8",[144,908,909,912],{},[52,910,911],{},"Inspect the full response text to see if there's content after the JSON.",[52,913,914],{},"Check backend logs for exception stacks being written to the response.",[95,916,196],{"id":917},"solutions-8",[49,919,920,923],{},[52,921,922],{},"Ensure each response is either pure JSON or pure HTML, not mixed.",[52,924,925,926,929],{},"For error responses, use a consistent JSON structure (e.g., ",[15,927,928],{},"error"," field) and avoid appending HTML.",[88,931],{},[41,933,935,936],{"id":934},"scenario-10-unvalidated-user-input-or-third-party-data-passed-to-jsonparse","Scenario 10: Unvalidated User Input or Third-Party Data Passed to ",[15,937,17],{},[95,939,98],{"id":940},"symptoms-9",[49,942,943,949],{},[52,944,945,946,948],{},"Frontend\u002Fbackend directly calls ",[15,947,17],{}," on user input, third-party webhooks, or queue messages.",[52,950,951],{},"When the data is invalid, it throws exceptions and can break the entire request flow.",[95,953,257],{"id":954},"causes-7",[49,956,957,960],{},[52,958,959],{},"Missing pre-validation: length, character set, structure, etc.",[52,961,962],{},"Assuming \"the other party will always send valid JSON\".",[95,964,142],{"id":965},"debugging-steps-9",[144,967,968,985],{},[52,969,970,971,973,974],{},"Review all ",[15,972,17],{}," call sites in your code:\n",[49,975,976,979],{},[52,977,978],{},"Is the data source trusted?",[52,980,981,982,175],{},"Is it wrapped in ",[15,983,984],{},"try...catch",[52,986,987,988,990],{},"For failing samples, paste them into the ",[35,989,38],{"href":37}," to see specific errors.",[95,992,196],{"id":993},"solutions-9",[49,995,996,1021],{},[52,997,998,999],{},"For all external input:\n",[49,1000,1001,1004,1007,1010,1015,1018],{},[52,1002,1003],{},"Set a realistic byte-size limit before parsing untrusted input (e.g., max 1MB).",[52,1005,1006],{},"Decode input as UTF-8.",[52,1008,1009],{},"Reject malformed encoding where your platform exposes decoding errors.",[52,1011,1012,1013,218],{},"Parse inside ",[15,1014,984],{},[52,1016,1017],{},"Validate the parsed value against a schema or application rules.",[52,1019,1020],{},"Avoid logging full untrusted payloads, especially if they may contain secrets.",[52,1022,1023,1024,130,1027,218],{},"JSON allows Unicode strings — don't restrict to \"printable ASCII\" only, as that would reject valid international data like ",[15,1025,1026],{},"\"São Paulo\"",[15,1028,1029],{},"\"日本語\"",[11,1031,1032,1033,1037],{},"Once text can be parsed successfully, syntax validation is only the first step. Use ",[35,1034,1036],{"href":1035},"\u002Fblog\u002Fjson-validation-syntax-vs-schema","JSON Schema validation to check required fields, data types, and allowed values"," before accepting the data in your application.",[88,1039],{},[41,1041,1043],{"id":1042},"troubleshooting-checklist-worth-bookmarking","Troubleshooting Checklist (Worth Bookmarking)",[11,1045,1046],{},"When you hit a \"JSON parse failed\" error, troubleshoot in this order:",[144,1048,1049,1055,1063,1076,1082,1095,1101,1107],{},[52,1050,1051,1054],{},[24,1052,1053],{},"Check status code",": is it 2xx?",[52,1056,1057,1060,1061,175],{},[24,1058,1059],{},"Check Content-Type",": is it ",[15,1062,174],{},[52,1064,1065,166,1068],{},[24,1066,1067],{},"Inspect response content",[49,1069,1070,1073],{},[52,1071,1072],{},"Is it pure JSON, or HTML\u002Ftext?",[52,1074,1075],{},"Are there extra characters before\u002Fafter?",[52,1077,1078,1081],{},[24,1079,1080],{},"Check size",": is it unusually large (several MB+)?",[52,1083,1084,166,1087],{},[24,1085,1086],{},"Validate with a tool",[49,1088,1089],{},[52,1090,1091,1092,1094],{},"Paste the response into the ",[35,1093,38],{"href":37}," to automatically check syntax errors.",[52,1096,1097,1100],{},[24,1098,1099],{},"Check encoding",": is there a BOM or non-UTF-8 encoding?",[52,1102,1103,1106],{},[24,1104,1105],{},"Check logs",": does the backend log show exception stacks written to the response?",[52,1108,1109,166,1112],{},[24,1110,1111],{},"Check code",[49,1113,1114,1122],{},[52,1115,1116,1117,1119,1120,175],{},"Is ",[15,1118,17],{}," wrapped in ",[15,1121,984],{},[52,1123,1124],{},"Are you trying to parse non-2xx responses?",[88,1126],{},[41,1128,1130],{"id":1129},"how-to-prevent-json-parse-failures","How to Prevent JSON Parse Failures?",[144,1132,1133,1155,1185,1208],{},[52,1134,1135,1138],{},[24,1136,1137],{},"Standardize API Contracts",[49,1139,1140,1146,1152],{},[52,1141,1142,1143],{},"Success response: ",[15,1144,1145],{},"{ \"success\": true, \"data\": {...} }",[52,1147,1148,1149],{},"Error response: ",[15,1150,1151],{},"{ \"success\": false, \"error\": { \"code\": \"...\", \"message\": \"...\" } }",[52,1153,1154],{},"All responses are pure JSON, with no extra text.",[52,1156,1157,1160],{},[24,1158,1159],{},"Unified Parsing Logic on the Frontend",[49,1161,1162,1182],{},[52,1163,1164,1165,1168,1169],{},"Encapsulate a ",[15,1166,1167],{},"fetchJson"," utility:\n",[49,1170,1171,1173,1177],{},[52,1172,1053],{},[52,1174,158,1175],{},[15,1176,161],{},[52,1178,1179,1180],{},"Then call ",[15,1181,17],{},[52,1183,1184],{},"Route all API calls through this function to reduce repeated mistakes.",[52,1186,1187,1190],{},[24,1188,1189],{},"Logging and Monitoring",[49,1191,1192,1205],{},[52,1193,1194,1195],{},"For failed parses, log:\n",[49,1196,1197,1200,1202],{},[52,1198,1199],{},"Status code",[52,1201,161],{},[52,1203,1204],{},"First 1KB of the response (sanitized)",[52,1206,1207],{},"This makes it easier to tell whether it's a backend or network issue.",[52,1209,1210,1213],{},[24,1211,1212],{},"Use Tools Effectively",[49,1214,1215,1232],{},[52,1216,1217,1218],{},"During development:\n",[49,1219,1220,1226],{},[52,1221,1222,1223,1225],{},"Use the ",[35,1224,38],{"href":37}," to quickly validate API responses.",[52,1227,1228,1231],{},[35,1229,1230],{"href":37},"Format complex structures"," before reading them.",[52,1233,1234,1235],{},"For production issues:\n",[49,1236,1237],{},[52,1238,1239],{},"Paste problematic samples into the editor to quickly locate syntax errors.",[88,1241],{},[41,1243,1245],{"id":1244},"summary","Summary",[49,1247,1248,1251,1254],{},[52,1249,1250],{},"\"JSON parse failed\" can have many causes: HTML error pages, format errors, encoding issues, truncated responses, double serialization, and more.",[52,1252,1253],{},"A systematic troubleshooting flow (status code → Content-Type → response content → tool validation) can significantly reduce debugging time.",[52,1255,1256],{},"In the long run, standardizing API contracts, encapsulating parsing logic, and using validation tools are key to minimizing these issues.",[29,1258,1259],{},[11,1260,1261,1262,1264],{},"Next time you hit a JSON parse error, try pasting the response into the ",[35,1263,38],{"href":37}," first to quickly confirm whether it's a syntax issue, then decide whether to fix it on the frontend or escalate to backend debugging.",[41,1266,1268],{"id":1267},"whats-next","What's Next?",[49,1270,1271,1277,1284],{},[52,1272,1273,1274,218],{},"Once the text can be parsed, syntax validation is only the first layer. Learn how to use ",[35,1275,1276],{"href":1035},"JSON Schema validation to check structure, required fields, and data types",[52,1278,1279,1280,218],{},"For a foundational overview of JSON structure and syntax rules, see ",[35,1281,1283],{"href":1282},"\u002Fblog\u002Fwhat-is-json","What Is JSON?",[52,1285,1286,1287,218],{},"For API design patterns and response structure best practices, see ",[35,1288,1290],{"href":1289},"\u002Fblog\u002Fjson-best-practices","JSON Best Practices",{"title":371,"searchDepth":1292,"depth":1292,"links":1293},2,[1294,1295,1302,1309,1315,1321,1327,1333,1339,1345,1351,1358,1359,1360,1361],{"id":43,"depth":1292,"text":44},{"id":92,"depth":1292,"text":93,"children":1296},[1297,1299,1300,1301],{"id":97,"depth":1298,"text":98},3,{"id":122,"depth":1298,"text":123},{"id":141,"depth":1298,"text":142},{"id":195,"depth":1298,"text":196},{"id":230,"depth":1292,"text":1303,"children":1304},"Scenario 2: Content-Type Is Not application\u002Fjson",[1305,1306,1307,1308],{"id":236,"depth":1298,"text":98},{"id":256,"depth":1298,"text":257},{"id":277,"depth":1298,"text":142},{"id":296,"depth":1298,"text":196},{"id":323,"depth":1292,"text":324,"children":1310},[1311,1312,1313,1314],{"id":327,"depth":1298,"text":98},{"id":355,"depth":1298,"text":356},{"id":398,"depth":1298,"text":142},{"id":414,"depth":1298,"text":196},{"id":427,"depth":1292,"text":428,"children":1316},[1317,1318,1319,1320],{"id":431,"depth":1298,"text":98},{"id":457,"depth":1298,"text":257},{"id":472,"depth":1298,"text":142},{"id":515,"depth":1298,"text":196},{"id":542,"depth":1292,"text":543,"children":1322},[1323,1324,1325,1326],{"id":549,"depth":1298,"text":98},{"id":577,"depth":1298,"text":257},{"id":591,"depth":1298,"text":142},{"id":608,"depth":1298,"text":196},{"id":637,"depth":1292,"text":638,"children":1328},[1329,1330,1331,1332],{"id":641,"depth":1298,"text":98},{"id":656,"depth":1298,"text":257},{"id":667,"depth":1298,"text":142},{"id":678,"depth":1298,"text":196},{"id":698,"depth":1292,"text":699,"children":1334},[1335,1336,1337,1338],{"id":702,"depth":1298,"text":98},{"id":720,"depth":1298,"text":257},{"id":728,"depth":1298,"text":142},{"id":761,"depth":1298,"text":196},{"id":774,"depth":1292,"text":775,"children":1340},[1341,1342,1343,1344],{"id":778,"depth":1298,"text":98},{"id":807,"depth":1298,"text":257},{"id":818,"depth":1298,"text":142},{"id":829,"depth":1298,"text":196},{"id":872,"depth":1292,"text":873,"children":1346},[1347,1348,1349,1350],{"id":876,"depth":1298,"text":98},{"id":895,"depth":1298,"text":257},{"id":906,"depth":1298,"text":142},{"id":917,"depth":1298,"text":196},{"id":934,"depth":1292,"text":1352,"children":1353},"Scenario 10: Unvalidated User Input or Third-Party Data Passed to JSON.parse",[1354,1355,1356,1357],{"id":940,"depth":1298,"text":98},{"id":954,"depth":1298,"text":257},{"id":965,"depth":1298,"text":142},{"id":993,"depth":1298,"text":196},{"id":1042,"depth":1292,"text":1043},{"id":1129,"depth":1292,"text":1130},{"id":1244,"depth":1292,"text":1245},{"id":1267,"depth":1292,"text":1268},"json_tools","2026-08-24T00:00:00.000Z","A practical guide to debugging JSON parse errors in real APIs, covering typical error messages, root causes, and step-by-step troubleshooting.",false,"md",null,"\u002Fblog\u002Fcover\u002Fen\u002Fjson-parse-error-debug-cover.svg","2026-09-03T00:00:00.000Z",[1371,1372],"en","zh-CN",{},true,"\u002Fen\u002Fblog\u002Fjson-parse-error-debug",{"slug":1377,"text":1378,"btn":1379},"json-editor","🚀 Validate your JSON first:","Open JSON Editor",{"title":5,"description":1364},"en\u002Fblog\u002Fjson-parse-error-debug",[1383,38,1384,1385,1386,17],"JSON","JSON Validator","API Debugging","Error Handling","IRM6Gkn-n4JrWkRL1W1vrEVS6vc0ryQO55leFG2MLTc",[1389,1392],{"path":1390,"title":1391},"\u002Fzh\u002Fblog\u002Fjson-best-practices","前后端项目中 JSON 的最佳实践：接口设计、性能与安全",{"path":1393,"title":1394},"\u002Fzh\u002Fblog\u002Fjson-parse-error-debug","JSON 解析失败怎么办？接口调试中的 10 个典型错误与排查步骤",1791273861924]