Unity-Technologies/UnityCsReference · error · JSONParseException
Invalid escape char '{}' near {}
Error message
Invalid escape char '{}' near {} What it means
Thrown by the Asset Store JSON parser when a backslash escape inside a JSON string is followed by a character that is not one of the valid JSON escape characters (\", \\, \/, \b, \f, \n, \r, \t, \u). The default branch of the escape-handling switch fires this error with the offending character.
Source
Thrown at Editor/Mono/AssetStore/Json.cs:586
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()
{
string resstr = "";
if (cur == '-')
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Locate the invalid escape character reported in the message and replace it with a valid JSON escape or the literal character.
- If the data is generated programmatically, use a proper JSON serializer (JsonUtility, System.Text.Json, Newtonsoft.Json) instead of manual string concatenation.
- Clear cached Asset Store data and re-download to rule out corruption.
- Sanitize the input string to strip or replace unsupported escape sequences before parsing.
Example fix
// before — invalid escape
string json = "{\"path\": \"C:\\\\x\\temp\"}";
// after — valid JSON escaping (forward slash or double backslash)
string json = "{\"path\": \"C:/temp\"}"; Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate escape sequences before parsing
static readonly HashSet<char> ValidEscapes = new HashSet<char> { '"', '\\', '/', 'b', 'f', 'n', 'r', 't', 'u' };
bool HasValidEscapes(string json)
{
for (int i = 0; i < json.Length - 1; i++)
{
if (json[i] == '\\')
{
char next = json[i + 1];
if (!ValidEscapes.Contains(next))
return false;
}
}
return true;
} Try / catch
try
{
var result = JSONParser.SimpleParse(jsonString);
}
catch (JSONParseException ex) when (ex.Message.Contains("Invalid escape char"))
{
Debug.LogError($"Invalid JSON escape: {ex.Message}. Sanitize input.");
} Prevention
- Never hand-build JSON strings; use a serializer.
- Be aware that C# string escapes (\0, \x, \v) are not valid in JSON.
- Run JSON through a validator or JSON.parse-equivalent before feeding to this parser.
- Double-check escaping when copy-pasting paths or regex from source code into JSON.
When it happens
Trigger: Parsing a JSON string that contains an invalid escape such as "\x41" or "\q". The character ncur is the invalid escape letter. Happens when deserializing Asset Store responses or hand-written JSON that uses non-standard (e.g. C-style) escape sequences not permitted by the JSON spec.
Common situations: Third-party tools generating non-JSON-compliant escape sequences, copy-paste from source code containing C# string escapes into JSON, corrupted or partially-truncated downloaded data from the Asset Store.
Related errors
- Invalid unicode escape char near {}
- End of json while parsing while parsing string 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/0d0689f51c0dead8.
Report an issue: GitHub.