{"record":{"id":"29740445a57a8afd","repo":"Unity-Technologies/UnityCsReference","slug":"key-not-string-type-at","errorCode":null,"errorMessage":"Key not string type at {}","messagePattern":"Key not string type at (.+?)","errorType":"exception","errorClass":"JSONParseException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetStore/Json.cs","lineNumber":495,"sourceCode":"                {\n                    Next();\n                    SkipWs();\n                }\n            }\n            Next();\n            return new JSONValue(arr);\n        }\n\n        private JSONValue ParseDict()\n        {\n            Next();\n            SkipWs();\n            Dictionary<string, JSONValue> dict = new Dictionary<string, JSONValue>();\n            while (cur != '}')\n            {\n                JSONValue key = ParseValue();\n                if (!key.IsString())\n                    throw new JSONParseException(\"Key not string type at \" + PosMsg());\n                SkipWs();\n                if (cur != ':')\n                    throw new JSONParseException(\"Missing dict entry delimiter ':' at \" + PosMsg());\n                Next();\n                dict.Add(key.AsString(), ParseValue());\n                SkipWs();\n                if (cur == ',')\n                {\n                    Next();\n                    SkipWs();\n                }\n            }\n            Next();\n            return new JSONValue(dict);\n        }\n\n        static readonly char[] endcodes = { '\\\\', '\"' };\n","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetStore/Json.cs#L477-L513","documentation":"ParseDict parses each key via ParseValue and then asserts key.IsString(); JSON requires object keys to be strings, so a key that parsed as a number, bool, null, object, or array triggers JSONParseException (\"Key not string type at <pos>\"). This catches malformed objects like {1: \"x\"} or {true: 1}.","triggerScenarios":"Hand-written or generated JSON with an unquoted numeric/boolean key; another serializer that emits non-string keys; a parser bug allowing an object as a key.","commonSituations":"Manually constructed JSON strings; concatenation building keys from variables without quoting; schema produced by a non-strict serializer.","solutions":["Quote all object keys (\"id\": ... not id: ...).","Build JSON with a proper serializer rather than string concatenation.","Validate/round-trip the JSON through a strict parser during development."],"exampleFix":"// before (malformed)\n// { 1: \"x\" }\n\n// after\n// { \"1\": \"x\" }","handlingStrategy":"validation","validationCode":"// Validate that object keys are quoted strings before parsing.\n// Simplest robust approach: build JSON with a serializer that always quotes keys.","typeGuard":null,"tryCatchPattern":"try { v = JSON.Parse(json); }\ncatch (JSONParseException ex) { /* ex.Message gives position of the bad key */ throw; }","preventionTips":["Always quote object keys.","Build JSON with a serializer, not string concatenation.","Round-trip JSON through a strict parser during development/tests."],"tags":["json","parse","malformed-input","schema","asset-store","unity"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}