System.JSON.TJSONPathParser

Delphi
TJSONPathParser = class
C++
class PASCALIMPLEMENTATION TJSONPathParser : public System::TObject
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | System.JSON.pas System.JSON.hpp |
System.JSON | System.JSON |
Description
Parser of a JSON path.
A JSON path is a string that defines a path to a specific item within JSON data. A JSON path is to JSON what XPath is to XML.
Supported JSON Path Syntax
TJSONPathParser implements a subset of the JSON path specification defined by Stefan Göessner. Specifically, supported elements are child operators (.
) for objects and subscript operators ([]
) for arrays. These operators do not support special expressions, they only support actual values.
This is an example of a JSON path that TJSONPathParser supports: "store.books[0].title".
Using TJSONPathParser
When you create an instance of TJSONPathParser, you must pass the target JSON path to the constructor.
Once you have an instance of TJSONPathParser, call NextToken to iterate through the tokens of the specified JSON path until IsEof is True
or NextToken returns an Error token.
NextToken may return any of the following tokens:
Token | Description |
---|---|
|
The next token in the JSON path is the index of an item of a JSON array. TokenArrayIndex contains the target index. |
|
The next token in the JSON path is the key of a key-value pair of a JSON object. TokenName contains the target key. |
|
You have reached the end of the JSON path. You cannot continue iterating through the path, if you call NextToken again on this instance of TJSONPathParser an exception raises. |
|
There is an error in the specified JSON path. You cannot continue iterating through the path, if you call NextToken again on this instance of TJSONPathParser an exception raises. |
Token contains the token that the last call to NextToken returned.
For a code example that shows how to use TJSONPathParser, see the implementation of TJSONIterator.Find.