{"record":{"id":"a883f5ae99ff55ca","repo":"JamesNK/Newtonsoft.Json","slug":"property-0-not-valid-on-1","errorCode":null,"errorMessage":"Property '{0}' not valid on {1}.","messagePattern":"Property '(.+?)' not valid on (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs","lineNumber":47,"sourceCode":"                        }\n                        else if (settings?.ErrorWhenNoMatch ?? false)\n                        {\n                            throw new JsonException(\"Property '{0}' does not exist on JObject.\".FormatWith(CultureInfo.InvariantCulture, Name));\n                        }\n                    }\n                    else\n                    {\n                        foreach (KeyValuePair<string, JToken?> p in o)\n                        {\n                            yield return p.Value!;\n                        }\n                    }\n                }\n                else\n                {\n                    if (settings?.ErrorWhenNoMatch ?? false)\n                    {\n                        throw new JsonException(\"Property '{0}' not valid on {1}.\".FormatWith(CultureInfo.InvariantCulture, Name ?? \"*\", t.GetType().Name));\n                    }\n                }\n            }\n        }\n    }\n}","sourceCodeStart":29,"sourceCodeEnd":53,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs#L29-L53","documentation":"Thrown during JSONPath evaluation when a property/field filter tries to access a named property on a token that is not a JObject, and ErrorWhenNoMatch is true. The FieldFilter can only read properties off objects, so encountering a JArray, JValue, or JProperty triggers the error reporting the property name and the actual token type.","triggerScenarios":"Calling SelectTokens(\"$.data.name\", errorWhenNoMatch: true) where 'data' is a JArray rather than a JObject. FieldFilter.cs:45-48 fires in the else branch (token is not JObject).","commonSituations":"Schema drift where an object field became an array; treating a list element as an object without first indexing into it; chaining a property access directly after a wildcard that resolves to a scalar.","solutions":["Insert an array index or wildcard between the array and the property, e.g. $.data[0].name or $.data[*].name.","Verify the token type at each path segment before drilling into a property.","Drop errorWhenNoMatch so a type mismatch yields zero results instead of throwing."],"exampleFix":"// before\ntoken.SelectTokens(\"$.data.name\", errorWhenNoMatch: true); // data is a JArray\n\n// after\ntoken.SelectTokens(\"$.data[*].name\", errorWhenNoMatch: false);","handlingStrategy":"type-guard","validationCode":"var node = token[\"data\"];\nif (node is JObject obj)\n{\n    var name = obj[\"name\"];\n}","typeGuard":"static bool IsJsonObject(JToken? t) => t is JObject;","tryCatchPattern":null,"preventionTips":["Confirm a node is a JObject before drilling into a named property.","Insert the correct array index/wildcard when chaining through arrays.","Keep errorWhenNoMatch off to avoid exceptions on type mismatches."],"tags":["jsonpath","type-mismatch","field-filter"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}