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

  1. Verify the JSON input is complete — check the byte count or file size against expected length.
  2. If reading from a stream or network response, ensure the entire response body is buffered before parsing.
  3. Log the raw JSON string and its length to confirm truncation.
  4. 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

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


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