JamesNK/Newtonsoft.Json · error · JsonException

Properties {0} not valid on {1}.

Error message

Properties {0} not valid on {1}.

What it means

Thrown during JSONPath evaluation when a multiple-field filter (e.g. $['a','b']) is applied to a token that is not a JObject, and ErrorWhenNoMatch is true. FieldMultipleFilter can only read properties off objects; a JArray, JValue, or JProperty triggers the error, listing all requested property names and the actual token type.

Source

Thrown at Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs:46

                    {
                        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

  1. Confirm the target token is a JObject before applying a multi-field indexer.
  2. Drop errorWhenNoMatch so a non-object target yields zero results.
  3. Add the correct array indexing step before the property access.

Example fix

// before
token.SelectTokens("$.data['x','y']", errorWhenNoMatch: true); // data is a JArray

// after
token.SelectTokens("$.data[0]['x','y']", errorWhenNoMatch: false);
Defensive patterns

Strategy: type-guard

Validate before calling

var node = token["data"];
if (node is JObject obj)
{
    var vals = obj.SelectTokens("['x','y']");
}

Type guard

static bool IsJsonObject(JToken? t) => t is JObject;

Prevention

When it happens

Trigger: Calling SelectTokens("$.data['x','y']", errorWhenNoMatch: true) where 'data' resolves to a JArray or scalar rather than a JObject. The non-object branch (FieldMultipleFilter.cs:44-51) fires.

Common situations: Schema drift where an object became a list; indexing multiple properties off a value that is actually an array; a polymorphic response returning different shapes per record.

Related errors


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