{"record":{"id":"5b1d119d278ee6ff","repo":"OrchardCMS/OrchardCore","slug":"can-t-use-the-non-numeric-key-child-key-inside-an-array","errorCode":null,"errorMessage":"Can't use the non numeric key '{child.Key}' inside an array.","messagePattern":"Can't use the non numeric key '(.+?)' inside an array\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Abstractions/Shell/Configuration/Internal/ConfigurationExtensions.cs","lineNumber":58,"sourceCode":"                    {\n                        jArray.Add(null);\n                    }\n                }\n\n                if (child.GetChildren().Any())\n                {\n                    jArray.Add(ToJsonNode(child));\n                }\n                else\n                {\n                    jArray.Add(child.Value);\n                }\n            }\n            else\n            {\n                if (jArray is not null)\n                {\n                    throw new FormatException($\"Can't use the non numeric key '{child.Key}' inside an array.\");\n                }\n\n                jObject ??= [];\n                if (child.GetChildren().Any())\n                {\n                    jObject.Add(child.Key, ToJsonNode(child));\n                }\n                else\n                {\n                    jObject.Add(child.Key, child.Value);\n                }\n            }\n        }\n\n        return jArray as JsonNode ?? jObject ?? [];\n    }\n\n    public static JsonObject ToJsonObject(this IDictionary<string, string> configurationData)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Abstractions/Shell/Configuration/Internal/ConfigurationExtensions.cs#L40-L76","documentation":"ToJsonNode is the mirror case of the numeric-key error: once a level has started building a JsonArray (numeric keys), any subsequent non-numeric key at the same level cannot be represented, so FormatException is thrown naming the key.","triggerScenarios":"A configuration level contains numeric keys ('0','1') and then a named key, e.g. 'Items:0', 'Items:1', plus 'Items:Name' — the named key hits the jArray-not-null branch and throws.","commonSituations":"Mixing array syntax and object syntax in appsettings after a manual edit; migration scripts writing both 'Foo:0' and 'Foo:Default'; different providers (env vars + JSON) contributing conflicting keys at the same path.","solutions":["Remove the non-numeric key from the array-shaped level, or restructure as an object with named keys.","Keep arrays pure: keys must be exactly 0..count-1 with no extra named entries.","Use GetDebugView() on IConfiguration to find which provider contributes the conflicting key.","Bind to a typed model (List<T> or Dictionary<string,T>) instead of ToJsonNode if the shape is mixed."],"exampleFix":"// before\n\"Items\": { \"0\": \"a\", \"1\": \"b\", \"Default\": \"a\" }\n// after\n\"Items\": [\"a\", \"b\"], \"Default\": \"a\"","handlingStrategy":"validation","validationCode":"var keys = configuration.GetChildren().Select(c => c.Key).ToList();\nbool mixed = keys.Any(k => int.TryParse(k, out _)) && keys.Any(k => !int.TryParse(k, out _));\nif (mixed) throw new FormatException(\"Config array level contains a non-numeric key.\");","typeGuard":"bool IsObjectShaped(IConfiguration c) => c.GetChildren().All(ch => !int.TryParse(ch.Key, out _));","tryCatchPattern":"try { var node = configuration.ToJsonNode(); }\ncatch (FormatException ex) when (ex.Message.Contains(\"non numeric key\")) { /* restructure keys or bind to Dictionary<string,T> */ }","preventionTips":["Never add named entries to sections intended as JSON arrays","Audit appsettings after manual edits for mixed key styles","Use dictionary binding for sections that legitimately mix keys"],"tags":["configuration","json","format"],"backgroundTag":"schema-validation-failed","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}