IssueRaiser

Add JsonPath support to JsonDocument/JsonElement

Hi, I'd like to request JsonPath support for querying the JsonDocument/JsonElement classes. JsonPath provides similar capability to XPath (and even Sql) in that it allows queries to be performed against Json documents. This currently represents a major gap for us shifting from Newtonsoft to system.text.json, as we provide JsonPath values as an input parameter to a data load process which can't be worked around via code. The JsonPath syntax is described [here](https://goessner.net/articles/JsonPath/). The equivalent functionality in the Newtonsoft library is: ```csharp var jsonPath = "$.my.path"; var json = JToken.Parse(jsonString); var token = json.SelectToken(jsonPath); ``` The following proposed syntax would work well in the JsonDocument structure: ```csharp var jsonPath = "$.my.path"; var jsonDoc = JsonDocument.Parse(json); var element = jsonDoc.SelectElement(jsonPath); //returns JsonElement var elements = jsonDoc.SelectElements(jsonPath); //returns JsonElement.ArrayEnumerator ``` Thanks.

Posted by gary-holland on Oct 4, 2019, 6:09 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

support (Other)

Add JsonPath support to JsonDocument/JsonElement

gary-hollandOct 4, 2019, 6:09 AM

Hi, I'd like to request JsonPath support for querying the JsonDocument/JsonElement classes. JsonPath provides similar capability to XPath (and even Sql) in that it allows queries to be performed against Json documents. This currently represents a major gap for us shifting from Newtonsoft to system.text.json, as we provide JsonPath values as an input parameter to a data load process which can't be worked around via code. The JsonPath syntax is described [here](https://goessner.net/articles/JsonPath/). The equivalent functionality in the Newtonsoft library is: ```csharp var jsonPath = "$.my.path"; var json = JToken.Parse(jsonString); var token = json.SelectToken(jsonPath); ``` The following proposed syntax would work well in the JsonDocument structure: ```csharp var jsonPath = "$.my.path"; var jsonDoc = JsonDocument.Parse(json); var element = jsonDoc.SelectElement(jsonPath); //returns JsonElement var elements = jsonDoc.SelectElements(jsonPath); //returns JsonElement.ArrayEnumerator ``` Thanks.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue