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

Functions

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

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()

bool check_json_depth ( size_t  depth)

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

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 occured. Can be nullptr.
[out]error_messageIf the text is not a valid JSON, this variable will contain a readable error message. Can be nullptr.
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.