{"record":{"id":"dc9c03e36b81c86b","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-parse-json-value-starting-with-at","errorCode":null,"errorMessage":"Cannot parse json value starting with '{}' at {}","messagePattern":"Cannot parse json value starting with '(.+?)' at (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":463,"sourceCode":"                    return ParseString();\n                case '-':\n                case '0':\n                case '1':\n                case '2':\n                case '3':\n                case '4':\n                case '5':\n                case '6':\n                case '7':\n                case '8':\n                case '9':\n                    return ParseNumber();\n                case 't':\n                case 'f':\n                case 'n':\n                    return ParseConstant();\n                default:\n                    throw new JSONParseException(\"Cannot parse json value starting with '\" + json.Substring(idx, 5) + \"' at \" + PosMsg());\n            }\n        }\n\n        private JSONValue ParseArray()\n        {\n            Next();\n            SkipWs();\n            List<JSONValue> arr = new List<JSONValue>();\n            while (cur != ']')\n            {\n                arr.Add(ParseValue());\n                SkipWs();\n                if (cur == ',')\n                {\n                    Next();\n                    SkipWs();\n                }\n            }","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L445-L481","documentation":"ParseValue dispatches on the current character: '{' for object, '[' for array, '\"' for string, '-' or digit for number, 't'/'f'/'n' for true/false/null. The default branch throws JSONParseException (\"Cannot parse json value starting with '<first 5 chars>' at <pos>\") for any other leading character. The placeholder shows the actual offending prefix so the bad byte is visible.","triggerScenarios":"Leading byte-order mark (BOM), HTML/markup returned instead of JSON (e.g. '<' from an error page), unstripped leading whitespace that was not consumed, control characters, or an encoding mismatch producing unexpected bytes.","commonSituations":"Server returns an HTML error page with 200 status; UTF-8 BOM not stripped; gzip body not decompressed; binary garbage from a wrong endpoint.","solutions":["Inspect the first characters of the input (the message already shows the first 5) to identify the stray byte/markup.","Strip a leading BOM and surrounding whitespace before parsing.","Verify the response Content-Type is JSON and that any compression was decoded.","Catch JSONParseException and surface the endpoint/length so misrouted responses are obvious."],"exampleFix":"// before\nvar v = JSON.Parse(responseBody); // body starts with '<' (HTML)\n\n// after\nstring body = responseBody.TrimStart('\\uFEFF').Trim();\nif (body.StartsWith(\"<\"))\n    throw new InvalidOperationException(\"Expected JSON, got markup: \" + body.Substring(0, Math.Min(80, body.Length)));\nvar v = JSON.Parse(body);","handlingStrategy":"validation","validationCode":"string CleanJson(string raw) {\n    var s = raw.TrimStart('\\uFEFF').Trim();\n    if (s.Length == 0 || (s[0] != '{' && s[0] != '[' && s[0] != '\"' && s[0] != '-' && !char.IsDigit(s[0]) && s[0] != 't' && s[0] != 'f' && s[0] != 'n'))\n        throw new InvalidOperationException(\"Input does not start with a JSON value: \" + s.Substring(0, System.Math.Min(40, s.Length)));\n    return s;\n}","typeGuard":null,"tryCatchPattern":"try { v = JSON.Parse(json); }\ncatch (JSONParseException ex) {\n    // ex.Message shows the first 5 chars; log endpoint + content-type to spot HTML/BOM\n    throw;\n}","preventionTips":["Strip a leading UTF-8 BOM and surrounding whitespace before parsing.","Verify the response Content-Type is JSON and that compression was decoded.","Inspect the first bytes (the message already shows the first 5) to catch HTML error pages."],"tags":["json","parse","malformed-input","encoding","asset-store","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}