Skip to content

JsonDocumentSelect is a class library to extract key and values from JSON (System.Text.Json.JsonDocument) with single line expressions (JsonPath)

License

Notifications You must be signed in to change notification settings

yufeiqi/JsonDocumentSelect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JsonDocumentSelect

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.

NuGet Package

How to use it

  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" } ]

Implementation

Because JsonDocumentSelect is using the same Json.net strategic for parsing and evaluation the following is a list of pieces were already implemented:

Filters:

  • ArrayIndexFilter
  • ArrayMultipleIndexFilter
  • ArraySliceFilter
  • FieldFilter
  • FieldMultipleFilter
  • QueryFilter
  • QueryScanFilter
  • RootFilter
  • ScanFilter
  • ScanMultipleFilter

Unit Test:

  • JPathParseTests
  • QueryExpressionTests
  • JPathExecuteTests

About

JsonDocumentSelect is a class library to extract key and values from JSON (System.Text.Json.JsonDocument) with single line expressions (JsonPath)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages