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

  1. Call SelectToken without errorWhenNoMatch so a missing property returns null instead of throwing.
  2. Verify the property name spelling and case against the actual JSON keys.
  3. 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

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


AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07). Data as JSON: /api/errors/12d99426a8e02fcd. Report an issue: GitHub.