MySQL 9.0.0
Source Code Documentation
json_path.h File Reference

This file contains interface support for the JSON path abstraction. More...

#include <assert.h>
#include <stddef.h>
#include <algorithm>
#include <new>
#include <string>
#include <utility>
#include "my_alloc.h"
#include "mysql/psi/psi_memory.h"
#include "prealloced_array.h"

Go to the source code of this file.

Classes

class  Json_array_index
 A class that represents the index of an element in a JSON array. More...
 
class  Json_path_leg
 One path leg in a JSON path expression. More...
 
struct  Json_path_leg::Array_range
 A structure that represents an array range. More...
 
class  Json_seekable_path
 A path expression which can be used to seek to a position inside a JSON value. More...
 
class  Json_path
 A JSON path expression. More...
 
class  Json_path_clone
 A lightweight path expression. More...
 

Typedefs

using Json_path_leg_pointers = Prealloced_array< const Json_path_leg *, 8 >
 
using Json_path_iterator = Json_path_leg_pointers::const_iterator
 

Enumerations

enum  enum_json_path_leg_type {
  jpl_member , jpl_array_cell , jpl_array_range , jpl_member_wildcard ,
  jpl_array_cell_wildcard , jpl_ellipsis
}
 The type of a Json_path_leg. More...
 

Functions

bool parse_path (size_t path_length, const char *path_expression, Json_path *path, size_t *bad_index)
 Initialize a Json_path from a path expression. More...
 
bool parse_path (const String &path_value, bool forbid_wildcards, Json_path *json_path)
 A helper function that uses the above one as workhorse. More...
 

Detailed Description

This file contains interface support for the JSON path abstraction.

The path abstraction is described by the functional spec attached to WL#7909.

Typedef Documentation

◆ Json_path_iterator

◆ Json_path_leg_pointers

Enumeration Type Documentation

◆ enum_json_path_leg_type

The type of a Json_path_leg.

Enumerator
jpl_member 

A path leg that represents a JSON object member (such as .name).

This path leg matches a single member in a JSON object.

jpl_array_cell 

A path leg that represents a JSON array cell (such as [10]).

This path leg matches a single element in a JSON object.

jpl_array_range 

A path leg that represents a range in a JSON array (such as [2 to 7]).

jpl_member_wildcard 

A path leg that represents the member wildcard.

A path leg that represents the member wildcard (.*), which matches all the members of a JSON object.

jpl_array_cell_wildcard 

A path leg that represents the array wildcard ([*]), which matches all the elements of a JSON array.

jpl_ellipsis 

A path leg that represents the ellipsis (**), which matches any JSON value and recursively all the JSON values nested within it if it is an object or an array.

Function Documentation

◆ parse_path() [1/2]

bool parse_path ( const String path_value,
bool  forbid_wildcards,
Json_path json_path 
)

A helper function that uses the above one as workhorse.

Entry point for for JSON_TABLE (Table_function_json class) and Json_path_cache. Raises an error if the path expression is syntactically incorrect. Raises an error if the path expression contains wildcard tokens but is not supposed to. Otherwise updates the supplied Json_path object with the parsed path.

Parameters
[in]path_valueA String to be interpreted as a path.
[in]forbid_wildcardsTrue if the path shouldn't contain * or **
[out]json_pathThe object that will hold the parsed path
Returns
false on success (valid path or NULL), true on error

◆ parse_path() [2/2]

bool parse_path ( size_t  path_length,
const char *  path_expression,
Json_path path,
size_t *  bad_index 
)

Initialize a Json_path from a path expression.

Stops parsing on the first error. It initializes the Json_path and returns false if the path is parsed successfully. Otherwise, it returns false. In that case, the output bad_index argument will contain an index into the path expression. The parsing failed near that index.

Parameters
[in]path_lengthThe length of the path expression.
[in]path_expressionThe string form of the path expression.
[out]pathThe Json_path object to be initialized.
[out]bad_indexIf null is returned, the parsing failed around here.
Returns
false on success, true on error

Initialize a Json_path from a path expression.