{"record":{"id":"9e10042b3110650d","repo":"Humanizr/Humanizer","slug":"expected-json-array","errorCode":null,"errorMessage":"Expected JSON array.","messagePattern":"Expected JSON array\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs","lineNumber":274,"sourceCode":"    ///    <code>\n    ///    tensMap:\n    ///      2: 'twenty'\n    ///      3: 'thirty'\n    ///    </code>\n    ///\n    /// The numeric-slot form keeps YAML readable by replacing alignment hacks such as leading\n    /// empty strings with explicit indices. Missing slots are emitted as empty strings.\n    /// </summary>\n    static string CreateStringArrayExpression(JsonElement arrayElement)\n    {\n        if (arrayElement.ValueKind == JsonValueKind.Object)\n        {\n            return CreateNumericSlotStringArrayExpression(arrayElement);\n        }\n\n        if (arrayElement.ValueKind != JsonValueKind.Array)\n        {\n            throw new InvalidOperationException(\"Expected JSON array.\");\n        }\n\n        var builder = new StringBuilder(\"new string[] { \");\n        var first = true;\n\n        foreach (var item in arrayElement.EnumerateArray())\n        {\n            if (item.ValueKind != JsonValueKind.String)\n            {\n                continue;\n            }\n\n            if (!first)\n            {\n                builder.Append(\", \");\n            }\n\n            builder.Append(QuoteLiteral(item.GetString()!));","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs#L256-L292","documentation":"CreateStringArrayExpression (GenerationHelpers.cs:265-275) accepts two shapes for a string-array field: a JSON Array (plain list) or a JSON Object (sparse numeric-slot mapping). Any other top-level kind (scalar, or sometimes null) throws. This emits unitsMap/tensMap-style C# string[] arrays from locale data.","triggerScenarios":"A field expected to be a list or indexed mapping is instead a scalar (e.g. 'unitsMap: \"zero\"') or null.","commonSituations":"A YAML list collapsed to a scalar through indentation; a value left as a placeholder string; wrong node referenced by a contract sourcePath.","solutions":["Provide the value as a YAML/JSON array (['zero','one',...]) or as an indexed mapping ({2: 'twenty', 3: 'thirty'}).","Check YAML indentation so the list items nest under the key.","Verify the contract sourcePath points at the list node, not a parent scalar."],"exampleFix":"# before\nunitsMap: 'zero'\n# after\nunitsMap:\n  - 'zero'\n  - 'one'\n  - 'two'","handlingStrategy":"type-guard","validationCode":"// A string-array field must be Array or Object (C#)\nif (arrayElement.ValueKind != JsonValueKind.Array && arrayElement.ValueKind != JsonValueKind.Object)\n    throw new InvalidOperationException(\"Expected JSON array or indexed object for string array\");","typeGuard":"static bool IsStringArrayShape(JsonElement el) =>\n    el.ValueKind == JsonValueKind.Array || el.ValueKind == JsonValueKind.Object;","tryCatchPattern":null,"preventionTips":["Author list fields as YAML sequences (indented '-') or indexed mappings, never scalars.","Check YAML indentation so items nest under the key.","Point contract sourcePaths at the list node, not a parent scalar."],"tags":["source-generator","build-time","engine-contract","yaml","json","locale-data"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}