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

  1. Locate the invalid escape character reported in the message and replace it with a valid JSON escape or the literal character.
  2. If the data is generated programmatically, use a proper JSON serializer (JsonUtility, System.Text.Json, Newtonsoft.Json) instead of manual string concatenation.
  3. Clear cached Asset Store data and re-download to rule out corruption.
  4. 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

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


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