Implements a JSONPath query using the jsoncons library.
More...
#include <JsonPath.hpp>
|
| | JsonPath (const std::string &pathString, bool textOnlyQuery) |
| | Constructor setting a JSONPath string and whether the result should be text-only. More...
|
| |
|
| bool | getBool (const jsoncons::json &json) const |
| | Gets a boolean result from performing the query on a parsed JSON document. More...
|
| |
| void | getFirst (const jsoncons::json &json, std::string &resultTo) const |
| | Gets the first match from performing the query on a parsed JSON document. More...
|
| |
| void | getAll (const jsoncons::json &json, std::vector< std::string > &resultTo) const |
| | Gets all matches from performing the query on a parsed JSON document. More...
|
| |
| void | getSubSets (const jsoncons::json &json, std::vector< jsoncons::json > &resultTo) const |
| | Gets all matching subsets from performing the query on a parsed JSON document. More...
|
| |
Implements a JSONPath query using the jsoncons library.
For more information about the jsoncons library, see its <a href="https://github.com/danielaparker/jsoncons> GitHub repository.
◆ JsonPath()
| crawlservpp::Query::JsonPath::JsonPath |
( |
const std::string & |
pathString, |
|
|
bool |
textOnlyQuery |
|
) |
| |
|
inline |
Constructor setting a JSONPath string and whether the result should be text-only.
- Parameters
-
| pathString | Const reference to a string containing the JSONPath expression. Will be trimmed before use. |
| textOnlyQuery | Set whether the query should result in raw text only. In case of an array, the full array will be returned by getFirst when the query is text-only. The same is true for getAll if there is only one match. |
- Exceptions
-
References crawlservpp::Helper::Strings::trim().
◆ getAll()
| void crawlservpp::Query::JsonPath::getAll |
( |
const jsoncons::json & |
json, |
|
|
std::vector< std::string > & |
resultTo |
|
) |
| const |
|
inline |
Gets all matches from performing the query on a parsed JSON document.
- Note
- If there is only one match and it is an array, its members will be returned separately, unless the query has been set to text-only on construction.
- Parameters
-
| json | Const reference to a JSON document parsed by the jsoncons library. |
| resultTo | Reference to a vector to which the results will be written. The vector will be cleared even if an error occurs during execution of the query. |
- Exceptions
-
| JsonPath::Exception | if no JSONPath query has been defined, an error occurs during execution of the query, or the query did not return an array. |
- See also
- JsonPath::JsonPath
Referenced by crawlservpp::Main::Server::tick().
◆ getBool()
| bool crawlservpp::Query::JsonPath::getBool |
( |
const jsoncons::json & |
json | ) |
const |
|
inline |
Gets a boolean result from performing the query on a parsed JSON document.
- Parameters
-
| json | Const reference to a JSON document parsed by the jsoncons library. |
- Returns
- True, if there is at least one match after performing the query on the document. False otherwise.
- Exceptions
-
| JsonPath::Exception | if no JSONPath query has been defined or an error occurs during execution of the query. |
Referenced by crawlservpp::Main::Server::tick().
◆ getFirst()
| void crawlservpp::Query::JsonPath::getFirst |
( |
const jsoncons::json & |
json, |
|
|
std::string & |
resultTo |
|
) |
| const |
|
inline |
Gets the first match from performing the query on a parsed JSON document.
- Note
- If the first match is an array, only the first element of it will be returned, unless the query has been set to text-only on construction.
- Parameters
-
| json | Const reference to a JSON document parsed by the jsoncons library. |
| resultTo | Reference to a string to which the result will be written. The string will be cleared even if an error occurs during execution of the query. |
- Exceptions
-
| JsonPath::Exception | if no JSONPath query has been defined, an error occurs during execution of the query, or the query did not return an array. |
- See also
- JsonPath::JsonPath
Referenced by crawlservpp::Main::Server::tick().
◆ getSubSets()
| void crawlservpp::Query::JsonPath::getSubSets |
( |
const jsoncons::json & |
json, |
|
|
std::vector< jsoncons::json > & |
resultTo |
|
) |
| const |
|
inline |
Gets all matching subsets from performing the query on a parsed JSON document.
The subsets will be saved as JSON documents as defined by the jsoncons library.
- Note
- If there is only one match and it is an array, its members will be returned separately, unless the query has been set to text-only on construction.
- Parameters
-
| json | Const reference to a JSON document parsed by the jsoncons library. |
| resultTo | Reference to a vector to which the results will be written. The vector will be cleared even if an error occurs during execution of the query. |
- Exceptions
-
| JsonPath::Exception | if no JSONPath query has been defined, an error occurs during execution of the query, or the query did not return an array. |
- See also
- JsonPath::JsonPath
Referenced by crawlservpp::Main::Server::tick().
The documentation for this class was generated from the following file: