{"record":{"id":"0fce7dcc0ca7e252","repo":"Humanizr/Humanizer","slug":"expected-json-object","errorCode":null,"errorMessage":"Expected JSON object.","messagePattern":"Expected JSON object\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs","lineNumber":407,"sourceCode":"                builder.Append(\", \");\n            }\n\n            builder.Append(\"[TimeUnit.\");\n            builder.Append(ToEnumMemberName(entry.Name));\n            builder.Append(\"] = GrammaticalGender.\");\n            builder.Append(ToEnumMemberName(entry.Value.GetString()!));\n            first = false;\n        }\n\n        builder.Append(\" }.ToFrozenDictionary()\");\n        return builder.ToString();\n    }\n\n    static string CreateTargetTypedConstructorExpression(JsonElement element, params JsonConstructorValueEmitter[] emitters)\n    {\n        if (element.ValueKind != JsonValueKind.Object)\n        {\n            throw new InvalidOperationException(\"Expected JSON object.\");\n        }\n\n        var builder = new StringBuilder(\"new(\");\n        AppendConstructorValues(builder, element, emitters);\n        builder.Append(')');\n        return builder.ToString();\n    }\n\n    static string CreateTypedConstructorArrayExpression(string elementTypeName, JsonElement arrayElement, params JsonConstructorValueEmitter[] emitters)\n    {\n        if (arrayElement.ValueKind != JsonValueKind.Array)\n        {\n            throw new InvalidOperationException(\"Expected JSON array.\");\n        }\n\n        var builder = new StringBuilder(\"new \");\n        builder.Append(elementTypeName);\n        builder.Append(\"[] { \");","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/GenerationHelpers.cs#L389-L425","documentation":"CreateTargetTypedConstructorExpression (GenerationHelpers.cs:403-408) emits a target-typed 'new(...)' constructor call from a JSON object's properties. It throws when the supplied element is not a JSON Object (e.g. an array or scalar), because constructor arguments are read from object properties.","triggerScenarios":"A contract member that should be a single object is given a JSON array or scalar at its sourcePath.","commonSituations":"A contract sourcePath points at a list where a single record is expected; data reshaped so a record became an array; wrong member kind declared in the contract.","solutions":["Ensure the element at the contract's sourcePath is a JSON object.","Correct the contract member kind (e.g. use the array constructor emitter) if the data is genuinely a list.","Fix the sourcePath to reference the single object node."],"exampleFix":"// before - array where object expected\n[ { \"base\": 10 } ]\n// after - object\n{ \"base\": 10 }","handlingStrategy":"type-guard","validationCode":"// Target-typed constructor input must be a JSON object (C#)\nif (element.ValueKind != JsonValueKind.Object)\n    throw new InvalidOperationException(\"Expected JSON object for constructor expression\");","typeGuard":"static bool IsJsonObject(JsonElement el) => el.ValueKind == JsonValueKind.Object;","tryCatchPattern":null,"preventionTips":["Ensure contract sourcePaths for constructor members point at a single object.","Pick the array-constructor emitter when the data is a list.","Validate the top-level ValueKind matches the emitter before invoking it."],"tags":["source-generator","build-time","engine-contract","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"}