{"record":{"id":"82d82ff722cf2634","repo":"Unity-Technologies/UnityCsReference","slug":"end-of-json-while-parsing-while-parsing-string-at","errorCode":null,"errorMessage":"End of json while parsing while parsing string at {}","messagePattern":"End of json while parsing while parsing string at (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":537,"sourceCode":"\n            while (idx < len)\n            {\n                int endidx = json.IndexOfAny(endcodes, idx);\n                if (endidx < 0)\n                    throw new JSONParseException(\"missing '\\\"' to end string at \" + PosMsg());\n\n                res += json.Substring(idx, endidx - idx);\n\n                if (json[endidx] == '\"')\n                {\n                    cur = json[endidx];\n                    idx = endidx;\n                    break;\n                }\n\n                endidx++; // get escape code\n                if (endidx >= len)\n                    throw new JSONParseException(\"End of json while parsing while parsing string at \" + PosMsg());\n\n                // char at endidx is \\\n                char ncur = json[endidx];\n                switch (ncur)\n                {\n                    case '\"':\n                        goto case '/';\n                    case '\\\\':\n                        goto case '/';\n                    case '/':\n                        res += ncur;\n                        break;\n                    case 'b':\n                        res += '\\b';\n                        break;\n                    case 'f':\n                        res += '\\f';\n                        break;","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L519-L555","documentation":"Inside ParseString, once a backslash is found the parser increments endidx to read the escape character; if that position is past the end of input (the input ended right after the backslash), it throws JSONParseException (\"End of json while parsing while parsing string at <pos>\"). The doubled word 'while parsing while parsing' is a typo in the original message but the meaning is a truncated escape sequence.","triggerScenarios":"Truncated input ending immediately after a backslash (e.g. \"abc\\<EOF>); a malformed escape where the following character was lost; streaming cut mid-escape.","commonSituations":"Network truncation mid-string; hand-built JSON with a dangling backslash; buffer underrun.","solutions":["Ensure the input is complete and that every backslash is followed by a valid escape character.","Validate input length/integrity before parsing.","Catch JSONParseException and surface the position to locate the dangling escape."],"exampleFix":"// before\n// { \"msg\": \"line1\\<EOF>\n\n// after\n// { \"msg\": \"line1\\nline2\" }","handlingStrategy":"validation","validationCode":"// Ensure no input ends mid-escape; read full body before parsing.\n// For generated JSON, ensure every backslash is followed by a valid escape char.","typeGuard":null,"tryCatchPattern":"try { v = JSON.Parse(json); }\ncatch (JSONParseException ex) { /* position near dangling backslash */ throw; }","preventionTips":["Read the full body before parsing to avoid mid-escape truncation.","When constructing escapes by hand, always follow '\\' with a valid escape character.","Use a serializer to produce escape sequences correctly."],"tags":["json","parse","truncated-input","string-escape","asset-store","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}