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

Implements an extended JSONPointer query using the rapidJSON library. More...

#include <JsonPointer.hpp>

Classes

class  Exception
 Class for JSONPointer exceptions. More...
 

Construction

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

Getters

bool getBool (const rapidjson::Document &doc) const
 Gets a boolean result from performing the query on a parsed JSON document. More...
 
void getFirst (const rapidjson::Document &doc, std::string &resultTo) const
 Gets the first match from performing the query on a parsed JSON document. More...
 
void getAll (const rapidjson::Document &doc, std::vector< std::string > &resultTo) const
 Gets all matches from performing the query on a parsed JSON document. More...
 
void getSubSets (const rapidjson::Document &doc, std::vector< rapidjson::Document > &resultTo) const
 Gets all matching subsets from performing the query on a parsed JSON document. More...
 

Detailed Description

Implements an extended JSONPointer query using the rapidJSON library.

For more information about the rapidJSON library, see its GitHub repository.

Different from the JSONPointer standard (and the library), multiple results are possible by using $$ as a placeholder for 0..n, where n is the number of matches minus 1.

Constructor & Destructor Documentation

◆ JsonPointer()

crawlservpp::Query::JsonPointer::JsonPointer ( const std::string &  pointerString,
bool  textOnlyQuery 
)
inline

Constructor setting a JSONPointer string and whether the result should be text-only.

Parameters
pointerStringConst reference to a string containing the JSONPointer expression. Will be trimmed before use.
textOnlyQuerySet whether the query should result in raw text only. In case of an array, the full array string will be returned by getFirst when the query is text-only. The same is true for getAll if there is only one match.
Exceptions
JsonPointer::Exceptionif the given string is empty after trimming, or it contains an invalid JSONPointer query.

References crawlservpp::Helper::Strings::replaceAll(), and crawlservpp::Helper::Strings::trim().

Member Function Documentation

◆ getAll()

void crawlservpp::Query::JsonPointer::getAll ( const rapidjson::Document &  doc,
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
docConst reference to a JSON document parsed by the rapidJSON 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
JsonPointer::Exceptionif parsing errors occured in the given JSON document or no valid JSONPointer query has been set.
See also
JsonPointer::JsonPointer

References crawlservpp::Helper::Strings::replaceAll(), and crawlservpp::Helper::Json::stringify().

Referenced by crawlservpp::Main::Server::tick().

◆ getBool()

bool crawlservpp::Query::JsonPointer::getBool ( const rapidjson::Document &  doc) const
inline

Gets a boolean result from performing the query on a parsed JSON document.

Parameters
docConst reference to a JSON document parsed by the rapidJSON library.
Returns
True, if there is at least one match after performing the query on the document. False otherwise.
Exceptions
JsonPointer::Exceptionif parsing errors occured in the given JSON document or no valid JSONPointer query has been set.

Referenced by crawlservpp::Main::Server::tick().

◆ getFirst()

void crawlservpp::Query::JsonPointer::getFirst ( const rapidjson::Document &  doc,
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
docConst reference to a JSON document parsed by the rapidJSON 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
JsonPointer::Exceptionif parsing errors occured in the given JSON document or no valid JSONPointer query has been set.
See also
JsonPointer::JsonPointer

References crawlservpp::Helper::Json::stringify().

Referenced by crawlservpp::Main::Server::tick().

◆ getSubSets()

void crawlservpp::Query::JsonPointer::getSubSets ( const rapidjson::Document &  doc,
std::vector< rapidjson::Document > &  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 rapidJSON 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
docConst 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
JsonPointer::Exceptionif parsing errors occured in the given JSON document or no valid JSONPointer query has been set.
See also
JsonPointer::JsonPointer

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

Referenced by crawlservpp::Main::Server::tick().


The documentation for this class was generated from the following file: