Unity-Technologies/UnityCsReference · error · JSONParseException
End of json while parsing while parsing string at {}
Error message
End of json while parsing while parsing string at {} What it means
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.
Source
Thrown at Editor/Mono/AssetStore/Json.cs:537
while (idx < len)
{
int endidx = json.IndexOfAny(endcodes, idx);
if (endidx < 0)
throw new JSONParseException("missing '\"' to end string at " + PosMsg());
res += json.Substring(idx, endidx - idx);
if (json[endidx] == '"')
{
cur = json[endidx];
idx = endidx;
break;
}
endidx++; // get escape code
if (endidx >= len)
throw new JSONParseException("End of json while parsing while parsing string at " + PosMsg());
// char at endidx is \
char ncur = json[endidx];
switch (ncur)
{
case '"':
goto case '/';
case '\\':
goto case '/';
case '/':
res += ncur;
break;
case 'b':
res += '\b';
break;
case 'f':
res += '\f';
break;View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
// { "msg": "line1\<EOF>
// after
// { "msg": "line1\nline2" } Defensive patterns
Strategy: validation
Validate before calling
// Ensure no input ends mid-escape; read full body before parsing. // For generated JSON, ensure every backslash is followed by a valid escape char.
Try / catch
try { v = JSON.Parse(json); }
catch (JSONParseException ex) { /* position near dangling backslash */ throw; } Prevention
- 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.
When it happens
Trigger: Truncated input ending immediately after a backslash (e.g. "abc\<EOF>); a malformed escape where the following character was lost; streaming cut mid-escape.
Common situations: Network truncation mid-string; hand-built JSON with a dangling backslash; buffer underrun.
Related errors
- missing '"' to end string at {}
- End of json while parsing while parsing unicode char near {}
- End of json while parsing at {}
- Cannot parse json value starting with '{}' at {}
- Key not string type at {}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/82d82ff722cf2634.
Report an issue: GitHub.