Unity-Technologies/UnityCsReference · error · JSONParseException
End of json while parsing while parsing string near {}
Error message
End of json while parsing while parsing string near {} What it means
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.
Source
Thrown at Editor/Mono/AssetStore/Json.cs:591
digit += json[endidx + 4];
try
{
int d = System.Int32.Parse(digit, System.Globalization.NumberStyles.AllowHexSpecifier);
res += (char)d;
}
catch (FormatException)
{
throw new JSONParseException("Invalid unicode escape char near " + PosMsg());
}
endidx += 4;
break;
default:
throw new JSONParseException("Invalid escape char '" + ncur + "' near " + PosMsg());
}
idx = endidx + 1;
}
if (idx >= len)
throw new JSONParseException("End of json while parsing while parsing string near " + PosMsg());
cur = json[idx];
Next();
return new JSONValue(res);
}
private JSONValue ParseNumber()
{
string resstr = "";
if (cur == '-')
{
resstr = "-";
Next();
}
while (cur >= '0' && cur <= '9')View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before — truncated string (no closing quote)
string json = "{\"name\": \"unity";
// after — properly closed
string json = "{\"name\": \"unity\"}"; Defensive patterns
Strategy: validation
Validate before calling
// Verify JSON string literals are properly terminated before parsing
bool HasBalancedStringQuotes(string json)
{
bool inString = false;
bool escaped = false;
foreach (char c in json)
{
if (escaped) { escaped = false; continue; }
if (c == '\\') { escaped = true; continue; }
if (c == '"') inString = !inString;
}
return !inString; // false = unterminated string
} Try / catch
try
{
var result = JSONParser.SimpleParse(jsonString);
}
catch (JSONParseException ex) when (ex.Message.Contains("End of json"))
{
Debug.LogError($"Truncated JSON input: {ex.Message}");
// Re-download or re-read the full payload
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid unicode escape char near {}
- Invalid escape char '{}' near {}
- Cannot convert string to float : '{}' at {}
- Invalid token at {}
- Tried to read non-string json value as string
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ad6a030f33550dda.
Report an issue: GitHub.