{"record":{"id":"db426c8173ad724f","repo":"JamesNK/Newtonsoft.Json","slug":"property-0-has-already-been-defined-in-schema","errorCode":null,"errorMessage":"Property {0} has already been defined in schema.","messagePattern":"Property (.+?) has already been defined in schema\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs","lineNumber":424,"sourceCode":"            {\n                CurrentSchema.AdditionalItems = BuildSchema(token);\n            }\n        }\n\n        private IDictionary<string, JsonSchema> ProcessProperties(JToken token)\n        {\n            IDictionary<string, JsonSchema> properties = new Dictionary<string, JsonSchema>();\n\n            if (token.Type != JTokenType.Object)\n            {\n                throw JsonException.Create(token, token.Path, \"Expected Object token while parsing schema properties, got {0}.\".FormatWith(CultureInfo.InvariantCulture, token.Type));\n            }\n\n            foreach (JProperty propertyToken in token)\n            {\n                if (properties.ContainsKey(propertyToken.Name))\n                {\n                    throw new JsonException(\"Property {0} has already been defined in schema.\".FormatWith(CultureInfo.InvariantCulture, propertyToken.Name));\n                }\n\n                properties.Add(propertyToken.Name, BuildSchema(propertyToken.Value));\n            }\n\n            return properties;\n        }\n\n        private void ProcessItems(JToken token)\n        {\n            CurrentSchema.Items = new List<JsonSchema>();\n\n            switch (token.Type)\n            {\n                case JTokenType.Object:\n                    CurrentSchema.Items.Add(BuildSchema(token));\n                    CurrentSchema.PositionalItemsValidation = false;\n                    break;","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs#L406-L442","documentation":"Thrown by JsonSchemaBuilder.ProcessProperties when the same property name appears more than once in a single 'properties' object of a JSON Schema document. JSON Schema (draft-3, which this builder targets) forbids duplicate keys in the properties map.","triggerScenarios":"Parsing a schema JSON where the properties object lists a key twice. Example: JsonSchema.Parse(\"{\\\"properties\\\":{\\\"name\\\":{},\\\"name\\\":{}}}\") — even though the JSON parser may deduplicate, the builder iterates JProperty tokens and detects the duplicate as stored/seen.","commonSituations":"Hand-authored schemas with copy/paste duplication; schema generation tools that merge property sets without dedup; JSON that was not validated for unique keys; concatenating schema fragments programmatically.","solutions":["Remove the duplicate property entry so each name appears once.","Deduplicate generated property maps before serializing the schema JSON.","Validate schema documents with a strict JSON parser that rejects duplicate keys."],"exampleFix":"// before\n// {\"properties\":{\"name\":{},\"name\":{\"type\":\"string\"}}}\n// after\n// {\"properties\":{\"name\":{\"type\":\"string\"}}}","handlingStrategy":"validation","validationCode":"static bool HasUniqueProperties(JObject schemaJson)\n{\n    var props = schemaJson[\"properties\"] as JObject;\n    if (props == null) return true;\n    var seen = new HashSet<string>();\n    foreach (var p in props.Properties())\n        if (!seen.Add(p.Name)) return false;\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { JsonSchema.Parse(json); }\ncatch (JsonException ex) when (ex.Message.StartsWith(\"Property\") && ex.Message.Contains(\"already been defined\"))\n{ /* duplicate property name; dedupe the source */ }","preventionTips":["Deduplicate property maps before serializing schema JSON.","Use a strict JSON reader that rejects duplicate keys.","Validate authored schemas before shipping."],"tags":["schema","json","jsonschema","duplicate","validation"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}