{"record":{"id":"ad6a030f33550dda","repo":"Unity-Technologies/UnityCsReference","slug":"end-of-json-while-parsing-while-parsing-string-nea","errorCode":null,"errorMessage":"End of json while parsing while parsing string near {}","messagePattern":"End of json while parsing while parsing string near (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":591,"sourceCode":"                        digit += json[endidx + 4];\n                        try\n                        {\n                            int d = System.Int32.Parse(digit, System.Globalization.NumberStyles.AllowHexSpecifier);\n                            res += (char)d;\n                        }\n                        catch (FormatException)\n                        {\n                            throw new JSONParseException(\"Invalid unicode escape char near \" + PosMsg());\n                        }\n                        endidx += 4;\n                        break;\n                    default:\n                        throw new JSONParseException(\"Invalid escape char '\" + ncur + \"' near \" + PosMsg());\n                }\n                idx = endidx + 1;\n            }\n            if (idx >= len)\n                throw new JSONParseException(\"End of json while parsing while parsing string near \" + PosMsg());\n\n            cur = json[idx];\n\n            Next();\n            return new JSONValue(res);\n        }\n\n        private JSONValue ParseNumber()\n        {\n            string resstr = \"\";\n\n            if (cur == '-')\n            {\n                resstr = \"-\";\n                Next();\n            }\n\n            while (cur >= '0' && cur <= '9')","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L573-L609","documentation":"Thrown when the parser reaches end of input while scanning a JSON string literal that was never closed with a double-quote. The message contains a duplicated 'while parsing' phrase which is a known cosmetic bug in the source. It means the input was truncated or the opening quote was never matched by a closing quote.","triggerScenarios":"Parsing JSON where a string value or key is missing its terminating double-quote (e.g. {\"key\": \"value). Occurs when a network stream is cut mid-transfer, a file is truncated, or a JSON builder omits a closing quote.","commonSituations":"Network timeouts or connection resets during Asset Store downloads, files truncated by disk-full conditions, manual JSON construction that forgets closing quotes, buffer-size limits cutting off long responses.","solutions":["Verify the JSON input is complete — check the byte count or file size against expected length.","If reading from a stream or network response, ensure the entire response body is buffered before parsing.","Log the raw JSON string and its length to confirm truncation.","Re-download or regenerate the source data to obtain a complete payload."],"exampleFix":"// before — truncated string (no closing quote)\nstring json = \"{\\\"name\\\": \\\"unity\";\n// after — properly closed\nstring json = \"{\\\"name\\\": \\\"unity\\\"}\";","handlingStrategy":"validation","validationCode":"// Verify JSON string literals are properly terminated before parsing\nbool HasBalancedStringQuotes(string json)\n{\n    bool inString = false;\n    bool escaped = false;\n    foreach (char c in json)\n    {\n        if (escaped) { escaped = false; continue; }\n        if (c == '\\\\') { escaped = true; continue; }\n        if (c == '\"') inString = !inString;\n    }\n    return !inString; // false = unterminated string\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = JSONParser.SimpleParse(jsonString);\n}\ncatch (JSONParseException ex) when (ex.Message.Contains(\"End of json\"))\n{\n    Debug.LogError($\"Truncated JSON input: {ex.Message}\");\n    // Re-download or re-read the full payload\n}","preventionTips":["Buffer the entire HTTP response body before parsing; do not parse partial streams.","Verify downloaded file sizes against expected Content-Length headers.","Use checksums (MD5/SHA) to detect truncated data.","Log the raw input length when parsing fails to diagnose truncation."],"tags":["json","parsing","asset-store","truncation","malformed-data"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}