{"record":{"id":"66468d036c80bd79","repo":"JamesNK/Newtonsoft.Json","slug":"expected-json-property-0","errorCode":null,"errorMessage":"Expected JSON property '{0}'.","messagePattern":"Expected JSON property '(.+?)'\\.","errorType":"exception","errorClass":"JsonSerializationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs","lineNumber":108,"sourceCode":"                {\n                    writer.WriteValue(keyValue);\n                }\n            }\n            else\n            {\n                writer.WriteNull();\n            }\n\n            writer.WriteEndObject();\n        }\n\n        private static void ReadAndAssertProperty(JsonReader reader, string propertyName)\n        {\n            reader.ReadAndAssert();\n\n            if (reader.TokenType != JsonToken.PropertyName || !string.Equals(reader.Value?.ToString(), propertyName, StringComparison.OrdinalIgnoreCase))\n            {\n                throw new JsonSerializationException(\"Expected JSON property '{0}'.\".FormatWith(CultureInfo.InvariantCulture, propertyName));\n            }\n        }\n\n        /// <summary>\n        /// Reads the JSON representation of the object.\n        /// </summary>\n        /// <param name=\"reader\">The <see cref=\"JsonReader\"/> to read from.</param>\n        /// <param name=\"objectType\">Type of the object.</param>\n        /// <param name=\"existingValue\">The existing value of object being read.</param>\n        /// <param name=\"serializer\">The calling serializer.</param>\n        /// <returns>The object value.</returns>\n        public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)\n        {\n            EnsureReflectionObject(objectType);\n            MiscellaneousUtils.Assert(_reflectionObject != null);\n\n            object entityKeyMember = _reflectionObject.Creator!();\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs#L90-L126","documentation":"Thrown by EntityKeyMemberConverter.ReadAndAssertProperty when the next JSON token is not the expected property name ('Key', 'Type', or 'Value' by default, or the resolver-renamed equivalents). EntityKeyMemberConverter serializes a System.Data.EntityKeyMember as an object with those three properties in order; on read it asserts each in sequence and throws if the stream deviates.","triggerScenarios":"Deserializing JSON into an EntityKeyMember when the JSON object is missing a required property or has them in the wrong order/naming. For example JSON with {\"key\":...} when a camelCase resolver is not configured, or a payload that omits 'Type' or 'Value'. Only available when HAVE_ENTITY_FRAMEWORK is defined.","commonSituations":"Receiving EntityKeyMember JSON from a source that renamed properties (camelCase vs PascalCase) without a matching contract resolver. Hand-editing the JSON and dropping a field. A producer that omits the Type field because the value was null. Version skew where the producer writes a different shape.","solutions":["Ensure the JSON object contains all three properties Key, Type, and Value with the exact casing expected (apply a DefaultContractResolver with the same naming policy on both ends).","If the producer uses camelCase, configure the serializer with CamelCasePropertyNamesContractResolver so 'key'/'type'/'value' match.","If you do not actually need EntityKeyMember serialization, remove the converter or avoid round-tripping EntityKeyMember over JSON.","Validate the payload schema before deserializing."],"exampleFix":"// before: producer emits camelCase, default reader expects PascalCase\n// { \"key\": \"Id\", \"type\": \"System.Int32\", \"value\": 7 }\nvar key = JsonConvert.DeserializeObject<EntityKeyMember>(json);\n\n// after: match naming on both sides\nvar settings = new JsonSerializerSettings\n{\n    ContractResolver = new CamelCasePropertyNamesContractResolver()\n};\nvar key = JsonConvert.DeserializeObject<EntityKeyMember>(json, settings);","handlingStrategy":"validation","validationCode":"// Validate the JSON shape before deserializing EntityKeyMember\nvar jo = JObject.Parse(json);\nforeach (var prop in new[] { \"Key\", \"Type\", \"Value\" })\n{\n    var name = resolver.GetResolvedPropertyName(prop);\n    if (jo.Property(name, StringComparison.OrdinalIgnoreCase) == null)\n        throw new InvalidDataException($\"Missing expected property '{prop}'\");\n}","typeGuard":"static bool HasEntityKeyShape(JObject o) =>\n    o.ContainsKey(\"Key\", StringComparison.OrdinalIgnoreCase)\n    && o.ContainsKey(\"Type\", StringComparison.OrdinalIgnoreCase)\n    && o.ContainsKey(\"Value\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { var k = serializer.Deserialize<EntityKeyMember>(reader); }\ncatch (JsonSerializationException ex) when (ex.Message.Contains(\"Expected JSON property\"))\n{\n    throw new InvalidDataException(\"EntityKeyMember JSON is missing a required property\", ex);\n}","preventionTips":["Use the same naming policy (e.g. CamelCasePropertyNamesContractResolver) on producer and consumer.","Validate the payload contains Key/Type/Value before deserializing.","Avoid round-tripping EntityKeyMember over JSON if not needed."],"tags":["deserialization","converter","entity-framework","schema-mismatch"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}