3

I know that I can do a wildcard search like this:

jObject.SelectTokens("items.*.name");

I build the search path at runtime, its not hardcoded. In certain cases, I need to do a search for something a bit more complex like "q*", so that would result in a search path of:

jObject.SelectTokens("items.q*.name");

Json.net doesn't seem to support that, so in cases like that, I change the search string to "items.*.name" and then use a Where clause with regex to filter down to the ones that match the wildcard, so, the regex might be:

^items\.q.*\.name$

That's a simple case, of course, but it could be multiple *'s along the path and it could be something like ".*v2.", etc.

If there is some way to do that natively in json.net (or a better way of doing the regex), I can get rid of the regex matching since that is where the profiler is saying an expense is.

dbc
  • 104,963
  • 20
  • 228
  • 340
SledgeHammer
  • 7,338
  • 6
  • 41
  • 86
  • Not sure if it's what you wanted, but you can use the [union operator](http://goessner.net/articles/JsonPath/) to select multiple specific properties, e.g. `jObject.SelectTokens("items['q1','q2'].name")`. – dbc Apr 23 '18 at 18:58

0 Answers0