Skip to content

Latest commit

 

History

History
34 lines (29 loc) · 1.2 KB

RegexQuery.md

File metadata and controls

34 lines (29 loc) · 1.2 KB

Load and query JSON with JToken.SelectToken

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

var array = JArray.Parse("""
                         [
                           {
                             'PackageId': 'Argon',
                             'Version': '11.0.1',
                             'ReleaseDate': '2018-02-17T00:00:00'
                           },
                           {
                             'PackageId': 'NUnit',
                             'Version': '3.9.0',
                             'ReleaseDate': '2017-11-10T00:00:00'
                           }
                         ]
                         """);

// Find packages
var packages = array.SelectTokens("$.[?(@.PackageId =~ /^Argon/)]").ToList();

foreach (var item in packages)
{
    Console.WriteLine((string) item["PackageId"]);
}

// Argon

snippet source | anchor