JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.76k stars 3.25k forks source link

Incorrect parsing of JSONPath query #2947

Open tmoers opened 5 months ago

tmoers commented 5 months ago

The following JSONPath selector fails

$.Sensors[?(@.SensorId=="left-id")].SensorName

to parse with the message

Unexpected character while parsing path query: "

Here is some minimal example to reproduce it:

var token = new Newtonsoft.Json.Linq.JValue(false);
token.SelectToken("$.Sensors[?(@.SensorId==\"left-id\")].SensorName", false);
elgonzo commented 5 months ago

Note that Newtonsoft.Json implements (with slight inaccuracies) only a very old style/version of JSONPath described at https://goessner.net/articles/JsonPath. Old-ish JSONPath specification drafts (including relatively recent ones, like the one from 2020) only allowed single quotes in JSONPath expression. Hence the error message.

tmoers commented 5 months ago

Oh, great.. I didn't realize. I just tried it and single quotes indeed works!