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 multiple-field filter (e.g. $['a','b']) runs against a JObject with ErrorWhenNoMatch enabled. Note the code at FieldMultipleFilter.cs:36-39 throws whenever ErrorWhenNoMatch is true on the very first name checked, even if that property exists, because the throw is not gated behind the property being absent (it lacks an else). Practically, any multi-field indexer against a JObject with errorWhenNoMatch=true triggers it.
Source
Thrown at Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs:38
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, JsonSelectSettings? settings)
{
foreach (JToken t in current)
{
if (t is JObject o)
{
foreach (string name in Names)
{
JToken? v = o[name];
if (v != null)
{
yield return v;
}
if (settings?.ErrorWhenNoMatch ?? false)
{
throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, name));
}
}
}
else
{
if (settings?.ErrorWhenNoMatch ?? false)
{
throw new JsonException("Properties {0} not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, string.Join(", ", Names.Select(n => "'" + n + "'")
#if !HAVE_STRING_JOIN_WITH_ENUMERABLE
.ToArray()
#endif
), t.GetType().Name));
}
}
}
}
}
}View on GitHub (pinned to 4f73e74372)
Solutions
- Call SelectTokens with errorWhenNoMatch=false (the default) when using multi-field indexers.
- Select each property individually with SelectToken and handle nulls explicitly if you need strict per-field reporting.
- Restructure the query to avoid the multi-field form under strict mode.
Example fix
// before
token.SelectTokens("$.user['first','last']", errorWhenNoMatch: true);
// after
token.SelectTokens("$.user['first','last']", errorWhenNoMatch: false); Defensive patterns
Strategy: try-catch
Validate before calling
// Avoid strict mode with multi-field indexers
var values = token.SelectTokens("$.user['first','last']", errorWhenNoMatch: false); Try / catch
try
{
var v = token.SelectTokens("$.user['first','last']", errorWhenNoMatch: true);
}
catch (JsonException ex) when (ex.Message.Contains("does not exist on JObject"))
{
// fall back to per-field selection
} Prevention
- Never combine multi-field indexers with errorWhenNoMatch=true.
- Select fields individually when you need per-field absence detection.
- Be aware the multi-field strict path throws on the first checked name.
When it happens
Trigger: Calling SelectTokens("$.user['first','last']", errorWhenNoMatch: true) on a JObject. The loop reaches the ErrorWhenNoMatch check and throws after evaluating the first name, regardless of whether that property is present.
Common situations: Selecting several optional properties at once with strict error mode; upgrading a single-field path to a multi-field path while keeping errorWhenNoMatch=true.
Related errors
- Property '{0}' does not exist on JObject.
- Property '{0}' not valid on {1}.
- Properties {0} not valid on {1}.
- Path returned multiple tokens.
- Index * not valid on {0}.
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/8fb55ace8d1836c9.
Report an issue: GitHub.