crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
crawlservpp::Query::JsonPath Class Reference

Implements a JSONPath query using the jsoncons library. More...

#include <JsonPath.hpp>

Classes

class  Exception
 Class for JSONPath exceptions. More...
 

Construction

 JsonPath (const std::string &pathString, bool textOnlyQuery)
 Constructor setting a JSONPath string and whether the result should be text-only. More...
 

Getters

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
pathStringConst reference to a string containing the JSONPath expression. Will be trimmed before use.
textOnlyQuerySet 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
JsonPath::Exceptionif the given string is empty after trimming.

References crawlservpp::Helper::Strings::trim().

Member Function Documentation

◆ 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
jsonConst reference to a JSON document parsed by the jsoncons library.
resultToReference 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::Exceptionif 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
jsonConst 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::Exceptionif 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
jsonConst reference to a JSON document parsed by the jsoncons library.
resultToReference 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::Exceptionif 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
jsonConst reference to a JSON document parsed by the jsoncons library.
resultToReference 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::Exceptionif 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: