MySQL 8.0.39
Source Code Documentation
json_syntax_check.h File Reference
#include "my_rapidjson_size_t.h"
#include "sql-common/json_error_handler.h"
#include <rapidjson/reader.h>
#include <functional>
#include <string>
#include <utility>

Go to the source code of this file.

Classes

class  Syntax_check_handler
 This class implements a handler for use with rapidjson::Reader when we want to check if a string is a valid JSON text. More...
 

Functions

bool check_json_depth (size_t depth, const JsonDocumentDepthHandler &handler)
 Check if the depth of a JSON document exceeds the maximum supported depth (JSON_DOCUMENT_MAX_DEPTH). More...
 
bool is_valid_json_syntax (const char *text, size_t length, size_t *error_offset, std::string *error_message, const JsonDocumentDepthHandler &depth_handler)
 Check if a string is a valid JSON. More...
 
std::pair< std::string, size_t > get_error_from_reader (const rapidjson::Reader &reader)
 Extract a readable error from a rapidjson reader and return it to the caller. More...
 

Function Documentation

◆ check_json_depth()

bool check_json_depth ( size_t  depth,
const JsonDocumentDepthHandler handler 
)

Check if the depth of a JSON document exceeds the maximum supported depth (JSON_DOCUMENT_MAX_DEPTH).

Raise an error if the maximum depth has been exceeded.

Parameters
[in]depththe current depth of the document
[in]handlercallback function that gets called when maximum depth is exceeded
Returns
true if the maximum depth is exceeded, false otherwise

◆ get_error_from_reader()

std::pair< std::string, size_t > get_error_from_reader ( const rapidjson::Reader &  reader)

Extract a readable error from a rapidjson reader and return it to the caller.

Parameters
[in]readerThe rapidjson reader to extract the error from.
Returns
A pair where the first element is a readable error and the second element is the position in the input string where the error was found.

◆ is_valid_json_syntax()

bool is_valid_json_syntax ( const char *  text,
size_t  length,
size_t *  error_offset,
std::string *  error_message,
const JsonDocumentDepthHandler depth_handler 
)

Check if a string is a valid JSON.

Parameters
[in]textA pointer to the start of the text
[in]lengthThe length of the text
[out]error_offsetIf the text is not a valid JSON, this variable will be set to the position in the input string where the error occurred. Can be nullptr.
[out]error_messageIf the text is not a valid JSON, this variable will contain a readable error message. Can be nullptr.
[in]depth_handlerPointer to a function that should handle error occurred when depth is exceeded.
Return values
trueif the input text is a valid JSON.
falseif the input text is not a valid JSON.