Unity-Technologies/UnityCsReference · error · JSONParseException
Invalid unicode escape char near {}
Error message
Invalid unicode escape char near {} What it means
Thrown by the Asset Store JSON parser when a \uXXXX unicode escape sequence inside a JSON string contains characters that are not valid hexadecimal digits. The parser extracts four characters after \u and calls Int32.Parse with AllowHexSpecifier; a FormatException from that call triggers this error. It indicates the JSON payload is malformed at the unicode escape position.
Source
Thrown at Editor/Mono/AssetStore/Json.cs:581
res += '\t';
break;
case 'u':
// Unicode char specified by 4 hex digits
string digit = "";
if (endidx + 4 >= len)
throw new JSONParseException("End of json while parsing while parsing unicode char near " + PosMsg());
digit += json[endidx + 1];
digit += json[endidx + 2];
digit += json[endidx + 3];
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()View on GitHub (pinned to 225b0fbdb5)
Solutions
- Inspect the raw JSON payload at the reported position to find the malformed \u escape and correct the hex digits.
- Clear the Asset Store cache (Library/PackageManager or Editor pref cache) and re-fetch the data to get a clean response.
- If the data originates from a server endpoint, verify the server-side JSON serialization handles unicode correctly.
- If you control the JSON producer, ensure all unicode codepoints are emitted as valid 4-digit hex \uXXXX sequences.
Example fix
// before — malformed payload
string json = "{\"name\": \"caf\\u00G9\"}";
// after — valid hex digits
string json = "{\"name\": \"caf\\u00e9\"}"; Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate \u escape sequences before parsing
bool HasValidUnicodeEscapes(string json)
{
for (int i = 0; i < json.Length - 5; i++)
{
if (json[i] == '\\' && i + 1 < json.Length && json[i + 1] == 'u')
{
for (int j = 2; j <= 5; j++)
{
char c = json[i + j];
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))
return false;
}
}
}
return true;
} Try / catch
try
{
var result = JSONParser.SimpleParse(jsonString);
}
catch (JSONParseException ex) when (ex.Message.Contains("unicode escape"))
{
// Log the raw JSON region and re-fetch or sanitize
Debug.LogError($"Malformed unicode escape in JSON: {ex.Message}");
} Prevention
- Always use a spec-compliant JSON serializer when producing JSON data.
- Validate JSON payloads against a JSON schema or linter before parsing.
- Cache responses with checksums to detect corruption on re-read.
- If consuming external JSON, run it through a strict JSON validator first.
When it happens
Trigger: Parsing a JSON string containing a \u escape followed by non-hex characters (e.g. "\u00GG" or "\u00"). Occurs when AssetStoreClient or AssetStoreTooling deserializes a response from the Unity Asset Store server that contains a corrupted or truncated unicode escape sequence.
Common situations: Truncated network responses from the Asset Store API, proxy or CDN corruption of JSON payloads, manually-edited or hand-crafted JSON cache files with invalid escapes, character encoding issues where multi-byte sequences are split.
Related errors
- Invalid escape char '{}' near {}
- End of json while parsing while parsing string near {}
- Cannot convert string to float : '{}' at {}
- Invalid token at {}
- End of json while parsing while parsing unicode char near {}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/81bbac6a5db23643.
Report an issue: GitHub.