JsonDocumentSelect is a class library to extract key and values from JSON (System.Text.Json.JsonDocument) with single line expressions (JsonPath)
The JsonPath parser is based on the Newtonsoft.Json and JsonDocumentPath
But the JsonDocumentPath not update for a long time and not accept my pr for a long time, so I decide to create the JsonDocumentSelect library.
string json = @"{
""persons"": [
{
""name"" : ""John"",
""age"": ""26""
},
{
""name"" : ""Jane"",
""age"": ""2""
}
]
}";
var models = JsonDocument.Parse(json);
var results = models.SelectElements("$.persons[*].name").ToList();
The result
[ { "Element": "John", "Name": "name" }, { "Element": "Jane", "Name": "name" } ]
Because JsonDocumentSelect is using the same Json.net strategic for parsing and evaluation the following is a list of pieces were already implemented:
- ArrayIndexFilter
- ArrayMultipleIndexFilter
- ArraySliceFilter
- FieldFilter
- FieldMultipleFilter
- QueryFilter
- QueryScanFilter
- RootFilter
- ScanFilter
- ScanMultipleFilter
- JPathParseTests
- QueryExpressionTests
- JPathExecuteTests