JamesNK/Newtonsoft.Json · error · JsonException
Property '{0}' does not exist on JObject.
Error message
Property '{0}' does not exist on JObject. What it means
Thrown during JSONPath evaluation when a single property/field filter accesses a named property on a JObject but that property does not exist, and ErrorWhenNoMatch is true. The FieldFilter looked up o[Name] and got null, so it reports the missing property name.
Source
Thrown at Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs:32
}
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
{
foreach (JToken t in current)
{
if (t is JObject o)
{
if (Name != null)
{
JToken? v = o[Name];
if (v != null)
{
yield return v;
}
else if (settings?.ErrorWhenNoMatch ?? false)
{
throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, Name));
}
}
else
{
foreach (KeyValuePair<string, JToken?> p in o)
{
yield return p.Value!;
}
}
}
else
{
if (settings?.ErrorWhenNoMatch ?? false)
{
throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name));
}
}
}View on GitHub (pinned to 4f73e74372)
Solutions
- Call SelectToken without errorWhenNoMatch so a missing property returns null instead of throwing.
- Verify the property name spelling and case against the actual JSON keys.
- Check token["user"]?["email"] using JObject indexing with null-conditional access before querying.
Example fix
// before
token.SelectToken("$.user.email", errorWhenNoMatch: true);
// after
var email = token.SelectToken("$.user.email", errorWhenNoMatch: false);
// email is null if absent, no exception Defensive patterns
Strategy: validation
Validate before calling
// Use non-strict mode so a missing property returns null
var value = token.SelectToken("$.user.email", errorWhenNoMatch: false);
if (value == null) { /* handle absence */ } Type guard
static bool HasProperty(JObject obj, string name) => obj[name] != null;
Prevention
- Default to errorWhenNoMatch=false for optional fields.
- Double-check property name spelling and case sensitivity.
- Use JObject indexer access with null-conditional operators for optional keys.
When it happens
Trigger: Calling SelectToken("$.user.email", errorWhenNoMatch: true) on a JObject 'user' that has no 'email' property. FieldFilter.cs:30-33 fires when o[Name] returns null and ErrorWhenNoMatch is set.
Common situations: Optional fields that are omitted from the response when null; schema version differences where a property was renamed or removed; typos in the path expression's property name.
Related errors
- Property '{0}' not valid on {1}.
- Property '{0}' does not exist on JObject.
- Path returned multiple tokens.
- Index * not valid on {0}.
- Step cannot be zero.
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/12d99426a8e02fcd.
Report an issue: GitHub.