MySQL 8.4.2
Source Code Documentation
json_syntax_check.cc File Reference
#include "sql-common/json_syntax_check.h"
#include <assert.h>
#include <string>
#include <utility>
#include "my_rapidjson_size_t.h"
#include <rapidjson/error/en.h>
#include <rapidjson/error/error.h>
#include <rapidjson/memorystream.h>
#include <rapidjson/reader.h>

Functions

bool is_valid_json_syntax (const char *text, size_t length, size_t *error_offset, std::string *error_message, const JsonErrorHandler &depth_handler)
 Check if a string is a valid JSON. More...
 
bool check_json_depth (size_t depth, const JsonErrorHandler &handler)
 Check if the depth of a JSON document exceeds the maximum supported depth (JSON_DOCUMENT_MAX_DEPTH). More...
 
bool check_json_depth (size_t depth, const JsonSerializationErrorHandler &handler)
 
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...
 

Variables

static constexpr int JSON_DOCUMENT_MAX_DEPTH = 100
 The maximum number of nesting levels allowed in a JSON document. More...
 

Function Documentation

◆ check_json_depth() [1/2]

bool check_json_depth ( size_t  depth,
const JsonErrorHandler 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

◆ check_json_depth() [2/2]

bool check_json_depth ( size_t  depth,
const JsonSerializationErrorHandler handler 
)

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

Variable Documentation

◆ JSON_DOCUMENT_MAX_DEPTH

constexpr int JSON_DOCUMENT_MAX_DEPTH = 100
staticconstexpr

The maximum number of nesting levels allowed in a JSON document.