{"record":{"id":"0d0689f51c0dead8","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-escape-char-near","errorCode":null,"errorMessage":"Invalid escape char '{}' near {}","messagePattern":"Invalid escape char '(.+?)' near (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":586,"sourceCode":"                        if (endidx + 4 >= len)\n                            throw new JSONParseException(\"End of json while parsing while parsing unicode char near \" + PosMsg());\n                        digit += json[endidx + 1];\n                        digit += json[endidx + 2];\n                        digit += json[endidx + 3];\n                        digit += json[endidx + 4];\n                        try\n                        {\n                            int d = System.Int32.Parse(digit, System.Globalization.NumberStyles.AllowHexSpecifier);\n                            res += (char)d;\n                        }\n                        catch (FormatException)\n                        {\n                            throw new JSONParseException(\"Invalid unicode escape char near \" + PosMsg());\n                        }\n                        endidx += 4;\n                        break;\n                    default:\n                        throw new JSONParseException(\"Invalid escape char '\" + ncur + \"' near \" + PosMsg());\n                }\n                idx = endidx + 1;\n            }\n            if (idx >= len)\n                throw new JSONParseException(\"End of json while parsing while parsing string near \" + PosMsg());\n\n            cur = json[idx];\n\n            Next();\n            return new JSONValue(res);\n        }\n\n        private JSONValue ParseNumber()\n        {\n            string resstr = \"\";\n\n            if (cur == '-')\n            {","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L568-L604","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — invalid escape\nstring json = \"{\\\"path\\\": \\\"C:\\\\\\\\x\\\\temp\\\"}\";\n// after — valid JSON escaping (forward slash or double backslash)\nstring json = \"{\\\"path\\\": \\\"C:/temp\\\"}\";","handlingStrategy":"validation","validationCode":"// Pre-validate escape sequences before parsing\nstatic readonly HashSet<char> ValidEscapes = new HashSet<char> { '\"', '\\\\', '/', 'b', 'f', 'n', 'r', 't', 'u' };\nbool HasValidEscapes(string json)\n{\n    for (int i = 0; i < json.Length - 1; i++)\n    {\n        if (json[i] == '\\\\')\n        {\n            char next = json[i + 1];\n            if (!ValidEscapes.Contains(next))\n                return false;\n        }\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = JSONParser.SimpleParse(jsonString);\n}\ncatch (JSONParseException ex) when (ex.Message.Contains(\"Invalid escape char\"))\n{\n    Debug.LogError($\"Invalid JSON escape: {ex.Message}. Sanitize input.\");\n}","preventionTips":["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."],"tags":["json","parsing","asset-store","escape-sequence","malformed-data"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}