Unity-Technologies/UnityCsReference · error · JSONParseException

End of json while parsing at {}

Error message

End of json while parsing at {}

What it means

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.

Source

Thrown at Editor/Mono/AssetStore/Json.cs:409

        /*
         * Parse the entire json data string into a JSONValue structure hierarchy
         */
        public JSONValue Parse()
        {
            cur = json[idx];
            return ParseValue();
        }

        private char Next()
        {
            if (cur == '\n')
            {
                line++;
                linechar = 0;
            }
            idx++;
            if (idx >= len)
                throw new JSONParseException("End of json while parsing at " + PosMsg());

            linechar++;

            int newPct = (int)((float)idx * 100f / (float)len);
            if (newPct != pctParsed)
            {
                pctParsed = newPct;
            }
            cur = json[idx];
            return cur;
        }

        private void SkipWs()
        {
            string ws = " \n\t\r";
            while (ws.IndexOf(cur) != -1) Next();
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Verify the input is complete before parsing (check length / Content-Length / read to EOF).
  2. Catch JSONParseException and treat it as a transient fetch failure: log, re-fetch, or abort with context.
  3. If reading incrementally, accumulate the full body before handing it to the parser.

Example fix

// before
var value = JSON.Parse(partialString); // partialString is truncated

// after
try {
    var value = JSON.Parse(fullString);
} catch (JSONParseException ex) {
    // log length + tail, re-fetch or abort
    throw new InvalidOperationException("Truncated JSON (len=" + fullString.Length + "): " + ex.Message, ex);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (string.IsNullOrEmpty(json) || json.Length < 2)
    throw new InvalidOperationException("JSON input too short / empty");

Try / catch

JSONValue v;
try { v = JSON.Parse(json); }
catch (JSONParseException ex) {
    throw new InvalidOperationException($"Truncated/invalid JSON (len={json.Length}): {ex.Message}", ex);
}

Prevention

When it happens

Trigger: 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.

Common situations: Streaming download interrupted; gzip/streaming not fully decompressed; copy-paste of JSON that cut off; asset-store response truncated.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/38adb00ac0b6aa8c. Report an issue: GitHub.