{"record":{"id":"38adb00ac0b6aa8c","repo":"Unity-Technologies/UnityCsReference","slug":"end-of-json-while-parsing-at","errorCode":null,"errorMessage":"End of json while parsing at {}","messagePattern":"End of json while parsing at (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":409,"sourceCode":"        /*\n         * Parse the entire json data string into a JSONValue structure hierarchy\n         */\n        public JSONValue Parse()\n        {\n            cur = json[idx];\n            return ParseValue();\n        }\n\n        private char Next()\n        {\n            if (cur == '\\n')\n            {\n                line++;\n                linechar = 0;\n            }\n            idx++;\n            if (idx >= len)\n                throw new JSONParseException(\"End of json while parsing at \" + PosMsg());\n\n            linechar++;\n\n            int newPct = (int)((float)idx * 100f / (float)len);\n            if (newPct != pctParsed)\n            {\n                pctParsed = newPct;\n            }\n            cur = json[idx];\n            return cur;\n        }\n\n        private void SkipWs()\n        {\n            string ws = \" \\n\\t\\r\";\n            while (ws.IndexOf(cur) != -1) Next();\n        }\n","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L391-L427","documentation":"The parser's Next() advances one character; if idx reaches len it throws JSONParseException (\"End of json while parsing at <pos>\") because the input ended before a complete value was read. This is the generic truncation signal: any incomplete value (number, object, array, constant) whose parse runs past the buffer terminates here.","triggerScenarios":"Parsing a truncated string (cut mid-number, mid-object, mid-array); a network read that returned a partial body; a file read that hit EOF early; a buffer sized too small.","commonSituations":"Streaming download interrupted; gzip/streaming not fully decompressed; copy-paste of JSON that cut off; asset-store response truncated.","solutions":["Verify the input is complete before parsing (check length / Content-Length / read to EOF).","Catch JSONParseException and treat it as a transient fetch failure: log, re-fetch, or abort with context.","If reading incrementally, accumulate the full body before handing it to the parser."],"exampleFix":"// before\nvar value = JSON.Parse(partialString); // partialString is truncated\n\n// after\ntry {\n    var value = JSON.Parse(fullString);\n} catch (JSONParseException ex) {\n    // log length + tail, re-fetch or abort\n    throw new InvalidOperationException(\"Truncated JSON (len=\" + fullString.Length + \"): \" + ex.Message, ex);\n}","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrEmpty(json) || json.Length < 2)\n    throw new InvalidOperationException(\"JSON input too short / empty\");","typeGuard":null,"tryCatchPattern":"JSONValue v;\ntry { v = JSON.Parse(json); }\ncatch (JSONParseException ex) {\n    throw new InvalidOperationException($\"Truncated/invalid JSON (len={json.Length}): {ex.Message}\", ex);\n}","preventionTips":["Read the full body to EOF and match Content-Length before parsing.","Treat JSONParseException as a transient fetch error: log length + tail and retry/abort.","Do not parse partial chunks; accumulate then parse once."],"tags":["json","parse","truncated-input","asset-store","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}