IJsonElement.Query

Syntax

Query(Path: String): IJsonArray;

Query(Path: String): Prognoz.Platform.Interop.ForeSystem.IJsonArray;

Parameters

Path. JSONPath query to get child elements.

Description

The Query method returns the array of elements obtained by executing a JSONPath query.

Comments

Information about creating a JSONPath query can be found in specialized documentation, for example, MSDN.

Example

Executing the example requires the JSON file: d:\Work\Json\data.json. The file has the following approximate structure:

JSON file

Add links to the ForeSystem (for the Fore.NET example) system assembly.

Sub UserProc;
Var
    Doc: IJsonDocument;
    JSONArray: IJsonArray;
Begin
    Doc := 
New JsonDocument.Create;
    Doc.ReadFromFile(
"d:\Work\Json\data.json");
    JSONArray := Doc.Root.Query(
"$.product[?(@.price > 50 && @.price < 350)]");
    Debug.WriteLine(
"Number of selected elements: " + JSONArray.Count.ToString);
End Sub UserProc;

Imports Prognoz.Platform.Interop.ForeSystem;

Sub UserProc();
Var
    Doc: IJsonDocument = 
New JsonDocumentClass();
    JSONArray: IJsonArray;
Begin
    Doc.ReadFromFile(
"d:\Work\Json1\data.json");
    JSONArray := Doc.Root.Query(
"$.product[?(@.price > 50 && @.price < 350)]");
    System.Diagnostics.Debug.WriteLine(
"Number of selected elements: " + JSONArray.Count.ToString());
End Sub;

After executing the example, the JSON structure will be read from the file. This structure will be requested to select elements according to the specified condition. The number of selected elements will be displayed in the development environment console.

See also:

IJsonElement