{"record":{"id":"1939d836210381be","repo":"Humanizr/Humanizer","slug":"indexed-string-arrays-require-string-values-prope","errorCode":null,"errorMessage":"Indexed string arrays require string values. Property '{property.Name}' was {property.Value.ValueKind}.","messagePattern":"Indexed string arrays require string values\\. Property '(.+?)' was (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs","lineNumber":317,"sourceCode":"\n    static string CreateNumericSlotStringArrayExpression(JsonElement objectElement)\n    {\n        if (!objectElement.EnumerateObject().Any())\n        {\n            return \"Array.Empty<string>()\";\n        }\n\n        var indexedValues = new SortedDictionary<int, string>();\n        foreach (var property in objectElement.EnumerateObject())\n        {\n            if (!int.TryParse(property.Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out var index) || index < 0)\n            {\n                throw new InvalidOperationException($\"Indexed string arrays require non-negative integer keys. Invalid key '{property.Name}'.\");\n            }\n\n            if (property.Value.ValueKind != JsonValueKind.String)\n            {\n                throw new InvalidOperationException($\"Indexed string arrays require string values. Property '{property.Name}' was {property.Value.ValueKind}.\");\n            }\n\n            indexedValues[index] = property.Value.GetString()!;\n        }\n\n        var builder = new StringBuilder(\"new string[] { \");\n        var first = true;\n        var lastIndex = indexedValues.Keys.Max();\n\n        for (var index = 0; index <= lastIndex; index++)\n        {\n            if (!first)\n            {\n                builder.Append(\", \");\n            }\n\n            builder.Append(QuoteLiteral(indexedValues.TryGetValue(index, out var value) ? value : string.Empty));\n            first = false;","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs#L299-L335","documentation":"In the same indexed-mapping path, CreateNumericSlotStringArrayExpression (GenerationHelpers.cs:315-318) requires each value to be a JSON string. A number, boolean, object, or array value fails the ValueKind check; the message reports the actual ValueKind to aid diagnosis.","triggerScenarios":"An indexed string-array mapping has a non-string value, e.g. {2: 20} (number) instead of {2: 'twenty'} (string).","commonSituations":"Unquoted numeric value that YAML parses as a number; boolean or null placeholder left in place of a real string.","solutions":["Quote the value so it is a string: 2: 'twenty'.","Replace any null/bool/object placeholder with the intended text.","Run a YAML linter that flags unquoted scalars in string-typed mappings."],"exampleFix":"# before\ntensMap:\n  2: 20\n  3: 30\n# after\ntensMap:\n  2: 'twenty'\n  3: 'thirty'","handlingStrategy":"validation","validationCode":"// Indexed string-array values must be strings (C#)\nforeach (var prop in obj.EnumerateObject())\n    if (prop.Value.ValueKind != JsonValueKind.String)\n        throw new InvalidOperationException($\"Index '{prop.Name}' value must be a string, was {prop.Value.ValueKind}\");","typeGuard":"static bool AllStringValues(JsonElement obj) =>\n    obj.EnumerateObject().All(p => p.Value.ValueKind == JsonValueKind.String);","tryCatchPattern":null,"preventionTips":["Quote string values in indexed mappings so they stay strings.","Avoid numeric/bool/null placeholders in string-typed maps.","Run a YAML linter flagging unquoted scalars in these maps."],"tags":["source-generator","build-time","engine-contract","yaml","json","type-mismatch","locale-data"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}