Click or drag to resize
Json.NET

JSON Path regex operator

 

This sample loads JSON and then queries values from it using SelectToken(String) with a regex JSON Path.

Sample
Usage
JArray packages = JArray.Parse(@"[
  {
    'PackageId': 'Newtonsoft.Json',
    'Version': '11.0.1',
    'ReleaseDate': '2018-02-17T00:00:00'
  },
  {
    'PackageId': 'NUnit',
    'Version': '3.9.0',
    'ReleaseDate': '2017-11-10T00:00:00'
  }
]");

// Find Newtonsoft packages
List<JToken> newtonsoftPackages = packages.SelectTokens(@"$.[?(@.PackageId =~ /^Newtonsoft\.(.*)$/)]").ToList();

foreach (JToken item in newtonsoftPackages)
{
    Console.WriteLine((string) item["PackageId"]);
}
// Newtonsoft.Json