MySQL 8.4.0
Source Code Documentation
Json_wrapper Class Reference

Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON values or JSON DOM values. More...

#include <json_dom.h>

Public Member Functions

const char * get_datetime_packed (char *buffer) const
 Get the wrapped datetime value in the packed format. More...
 
 Json_wrapper ()
 Create an empty wrapper. More...
 
 Json_wrapper (Json_dom *dom_value, bool alias=false)
 Wrap the supplied DOM value (no copy taken). More...
 
 Json_wrapper (Json_dom_ptr dom_value)
 Wrap the supplied DOM value. More...
 
void set_alias ()
 Only meaningful iff the wrapper encapsulates a DOM. More...
 
 Json_wrapper (const json_binary::Value &value)
 Wrap a binary value. More...
 
 Json_wrapper (const Json_wrapper &old)
 Copy constructor. More...
 
 Json_wrapper (Json_wrapper &&old) noexcept
 Move constructor. More...
 
Json_wrapperoperator= (const Json_wrapper &old)
 Assignment operator. More...
 
Json_wrapperoperator= (Json_wrapper &&old) noexcept
 Move-assignment operator. More...
 
 ~Json_wrapper ()
 
bool empty () const
 A Wrapper is defined to be empty if it is passed a NULL value with the constructor for JSON dom, or if the default constructor is used. More...
 
bool is_dom () const
 Does this wrapper contain a DOM? More...
 
Json_domto_dom ()
 Get the wrapped contents in DOM form. More...
 
const Json_domget_dom () const
 Gets a pointer to the wrapped Json_dom object, if this wrapper holds a DOM. More...
 
const json_binary::Valueget_binary_value () const
 Gets the wrapped json_binary::Value object, if this wrapper holds a binary JSON value. More...
 
Json_dom_ptr clone_dom () const
 Get the wrapped contents in DOM form. More...
 
bool to_binary (const JsonSerializationErrorHandler &error_handler, String *str) const
 Get the wrapped contents in binary value form. More...
 
bool is_binary_backed_by (const String *str) const
 Check if the wrapped JSON document is a binary value (a json_binary::Value), and if that binary is pointing to data stored in the given string. More...
 
bool to_string (String *buffer, bool json_quoted, const char *func_name, const JsonErrorHandler &depth_handler) const
 Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646. More...
 
void dbug_print (const char *message, const JsonErrorHandler &depth_handler) const
 Print this JSON document to the debug trace. More...
 
bool to_pretty_string (String *buffer, const char *func_name, const JsonErrorHandler &depth_handler) const
 Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646. More...
 
enum_json_type type () const
 Return the type of the wrapped JSON value. More...
 
enum_field_types field_type () const
 Return the MYSQL type of the opaque value, see type(). More...
 
Json_wrapper operator[] (size_t index) const
 If this wrapper holds a JSON array, get an array value by indexing into the array. More...
 
Json_wrapper lookup (const MYSQL_LEX_CSTRING &key) const
 If this wrapper holds a JSON object, get the value corresponding to the member key. More...
 
const char * get_data () const
 Get a pointer to the data of a JSON string or JSON opaque value. More...
 
size_t get_data_length () const
 Get the length to the data of a JSON string or JSON opaque value. More...
 
bool get_decimal_data (my_decimal *d) const
 Get the MySQL representation of a JSON decimal value. More...
 
double get_double () const
 Get the value of a JSON double number. More...
 
longlong get_int () const
 Get the value of a JSON signed integer number. More...
 
ulonglong get_uint () const
 Get the value of a JSON unsigned integer number. More...
 
void get_datetime (MYSQL_TIME *t) const
 Get the value of a JSON date/time value. More...
 
bool get_boolean () const
 Get a boolean value (a JSON true or false literal). More...
 
bool seek (const Json_seekable_path &path, size_t legs, Json_wrapper_vector *hits, bool auto_wrap, bool only_need_one)
 Finds all of the json sub-documents which match the path expression. More...
 
size_t length () const
 Compute the length of a document. More...
 
int compare (const Json_wrapper &other, const CHARSET_INFO *cs=nullptr) const
 Compare this JSON value to another JSON value. More...
 
longlong coerce_int (const JsonCoercionHandler &error_handler, bool *err, bool *unsigned_flag) const
 Extract an int (signed or unsigned) from the JSON if possible coercing if need be. More...
 
longlong coerce_int (const JsonCoercionHandler &error_handler) const
 Shorthand for coerce_int(error_handler, nullptr, nullptr). More...
 
double coerce_real (const JsonCoercionHandler &error_handler, bool *err) const
 Extract a real from the JSON if possible, coercing if need be. More...
 
double coerce_real (const JsonCoercionHandler &error_handler) const
 Shorthand for coerce_real(error_handler, nullptr). More...
 
my_decimalcoerce_decimal (const JsonCoercionHandler &error_handler, my_decimal *decimal_value, bool *err) const
 Extract a decimal from the JSON if possible, coercing if need be. More...
 
my_decimalcoerce_decimal (const JsonCoercionHandler &error_handler, my_decimal *decimal_value) const
 Shorthand for coerce_decimal(error_handler, decimal_value, nullptr). More...
 
bool coerce_date (const JsonCoercionHandler &error_handler, const JsonCoercionDeprecatedHandler &deprecation_checker, MYSQL_TIME *ltime, my_time_flags_t date_flags_arg=0) const
 Extract a date from the JSON if possible, coercing if need be. More...
 
bool coerce_time (const JsonCoercionHandler &error_handler, const JsonCoercionDeprecatedHandler &deprecation_checker, MYSQL_TIME *ltime) const
 Extract a time value from the JSON if possible, coercing if need be. More...
 
size_t make_sort_key (uchar *to, size_t length) const
 Make a sort key that can be used by filesort to order JSON values. More...
 
ulonglong make_hash_key (ulonglong hash_val) const
 Make a hash key that can be used by sql_executor.cc/unique_hash in order to support SELECT DISTINCT. More...
 
bool get_free_space (const JsonSerializationErrorHandler &error_handler, size_t *space) const
 Calculate the amount of unused space inside a JSON binary value. More...
 
bool attempt_binary_update (const Field_json *field, const Json_seekable_path &path, Json_wrapper *new_value, bool replace, String *result, bool *partially_updated, bool *replaced_path)
 Attempt a binary partial update by replacing the value at path with new_value. More...
 
bool binary_remove (const Field_json *field, const Json_seekable_path &path, String *result, bool *found_path)
 Remove a path from a binary JSON document. More...
 
void sort (const CHARSET_INFO *cs=nullptr)
 Sort contents. More...
 
void remove_duplicates (const CHARSET_INFO *cs=nullptr)
 Remove duplicate values. More...
 

Private Attributes

union {
   struct {
      Json_dom *   m_value
 
      bool   m_alias
 If true, don't deallocate m_dom_value in destructor. More...
 
   }   m_dom
 The DOM representation, only used if m_is_dom is true. More...
 
   json_binary::Value   m_value
 The binary representation, only used if m_is_dom is false. More...
 
}; 
 
bool m_is_dom
 Wraps a DOM iff true. More...
 

Detailed Description

Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON values or JSON DOM values.

The purpose of this is to allow uniform access for callers. It allows us to access binary JSON values without necessarily building a DOM (and thus having to read the entire value unless necessary, e.g. for accessing only a single array slot or object field).

Instances of this class are usually created on the stack. In some cases instances are cached in an Item and reused, in which case they are allocated from query-duration memory (by allocating them on a MEM_ROOT).

Constructor & Destructor Documentation

◆ Json_wrapper() [1/6]

Json_wrapper::Json_wrapper ( )
inline

Create an empty wrapper.

Cf empty().

◆ Json_wrapper() [2/6]

Json_wrapper::Json_wrapper ( Json_dom dom_value,
bool  alias = false 
)
explicit

Wrap the supplied DOM value (no copy taken).

The wrapper takes ownership, unless alias is true or set_alias is called after construction. In the latter case the lifetime of the DOM is determined by the owner of the DOM, so clients need to ensure that that lifetime is sufficient, lest dead storage is attempted accessed.

Parameters
[in,out]dom_valuethe DOM value
aliasWhether the wrapper is an alias to DOM

< no deallocation, make us empty

◆ Json_wrapper() [3/6]

Json_wrapper::Json_wrapper ( Json_dom_ptr  dom_value)
inlineexplicit

Wrap the supplied DOM value.

The wrapper takes over the ownership.

◆ Json_wrapper() [4/6]

Json_wrapper::Json_wrapper ( const json_binary::Value value)
explicit

Wrap a binary value.

Does not copy the underlying buffer, so lifetime is limited the that of the supplied value.

Parameters
[in]valuethe binary value

◆ Json_wrapper() [5/6]

Json_wrapper::Json_wrapper ( const Json_wrapper old)

Copy constructor.

Does a deep copy of any owned DOM. If a DOM os not owned (aliased), the copy will also be aliased.

◆ Json_wrapper() [6/6]

Json_wrapper::Json_wrapper ( Json_wrapper &&  old)
noexcept

Move constructor.

Take over the ownership of the other wrapper's DOM, unless it's aliased. If the other wrapper is aliased, this wrapper becomes an alias too. Any already owned DOM will be deallocated.

Parameters
oldthe wrapper whose contents to take over

◆ ~Json_wrapper()

Json_wrapper::~Json_wrapper ( )

Member Function Documentation

◆ attempt_binary_update()

bool Json_wrapper::attempt_binary_update ( const Field_json field,
const Json_seekable_path path,
Json_wrapper new_value,
bool  replace,
String result,
bool *  partially_updated,
bool *  replaced_path 
)

Attempt a binary partial update by replacing the value at path with new_value.

On successful completion, the updated document will be available in result, and this Json_wrapper will point to result instead of the original binary representation. The modifications that have been applied, will also be collected as binary diffs, which can be retrieved via TABLE::get_binary_diffs().

Parameters
fieldthe column being updated
paththe path of the value to update
new_valuethe new value
replacetrue if we use JSON_REPLACE semantics
[in,out]resultbuffer that holds the updated JSON document (is empty if no partial update has been performed on this Json_wrapper so far, or contains the binary representation of the document in this wrapper otherwise)
[out]partially_updatedgets set to true if partial update was successful, also if it was a no-op
[out]replaced_pathgets set to true if the path was replaced, will be false if this update is a no-op
Return values
falseif the update was successful, or if it was determined that a full update was needed
trueif an error occurred

◆ binary_remove()

bool Json_wrapper::binary_remove ( const Field_json field,
const Json_seekable_path path,
String result,
bool *  found_path 
)

Remove a path from a binary JSON document.

On successful completion, the updated document will be available in result, and this Json_wrapper will point to result instead of the original binary representation. The modifications that have been applied, will also be collected as binary diffs, which can be retrieved via TABLE::get_binary_diffs().

Parameters
fieldthe column being updated
paththe path to remove from the document
[in,out]resultbuffer that holds the updated JSON document (is empty if no partial update has been performed on this Json_wrapper so far, or contains the binary representation of the document in this wrapper otherwise)
[out]found_pathgets set to true if the path is found in the document, false otherwise
Return values
falseif the value was successfully updated
trueif an error occurred

◆ clone_dom()

Json_dom_ptr Json_wrapper::clone_dom ( ) const

Get the wrapped contents in DOM form.

Same as to_dom(), except it returns a clone of the original DOM instead of the actual, internal DOM tree.

Returns
pointer to a DOM object, or NULL if the DOM could not be allocated

◆ coerce_date()

bool Json_wrapper::coerce_date ( const JsonCoercionHandler error_handler,
const JsonCoercionDeprecatedHandler deprecation_checker,
MYSQL_TIME ltime,
my_time_flags_t  date_flags_arg = 0 
) const

Extract a date from the JSON if possible, coercing if need be.

Parameters
[in]error_handlerfunction to be called on conversion errors
[in]deprecation_checkerfunction to be called to check for deprecated datetime format in ltime
[in,out]ltimea value buffer
[in]date_flags_argFlags to use for string -> date conversion
Returns
json value coerced to date

◆ coerce_decimal() [1/2]

my_decimal * Json_wrapper::coerce_decimal ( const JsonCoercionHandler error_handler,
my_decimal decimal_value 
) const
inline

Shorthand for coerce_decimal(error_handler, decimal_value, nullptr).

◆ coerce_decimal() [2/2]

my_decimal * Json_wrapper::coerce_decimal ( const JsonCoercionHandler error_handler,
my_decimal decimal_value,
bool *  err 
) const

Extract a decimal from the JSON if possible, coercing if need be.

Parameters
[in]error_handlerfunction to be called on conversion errors
[in,out]decimal_valuea value buffer
[out]errtrue <=> error occur during coercion
Returns
json value coerced to decimal

◆ coerce_int() [1/2]

longlong Json_wrapper::coerce_int ( const JsonCoercionHandler error_handler) const
inline

Shorthand for coerce_int(error_handler, nullptr, nullptr).

◆ coerce_int() [2/2]

longlong Json_wrapper::coerce_int ( const JsonCoercionHandler error_handler,
bool *  err,
bool *  unsigned_flag 
) const

Extract an int (signed or unsigned) from the JSON if possible coercing if need be.

Parameters
[in]error_handlerfunction to be called on conversion errors
[out]errtrue <=> error occur during coercion
[out]unsigned_flagWhether the value read from JSON data is unsigned
Returns
json value coerced to int

◆ coerce_real() [1/2]

double Json_wrapper::coerce_real ( const JsonCoercionHandler error_handler) const
inline

Shorthand for coerce_real(error_handler, nullptr).

◆ coerce_real() [2/2]

double Json_wrapper::coerce_real ( const JsonCoercionHandler error_handler,
bool *  err 
) const

Extract a real from the JSON if possible, coercing if need be.

Parameters
[in]error_handlerfunction to be called on conversion errors
[out]errtrue <=> error occur during coercion
Returns
json value coerced to real

◆ coerce_time()

bool Json_wrapper::coerce_time ( const JsonCoercionHandler error_handler,
const JsonCoercionDeprecatedHandler deprecation_checker,
MYSQL_TIME ltime 
) const

Extract a time value from the JSON if possible, coercing if need be.

Parameters
[in]error_handlerfunction to be called on conversion errors
[in]deprecation_checkerfunction to be called to check for deprecated datetime format in ltime
[in,out]ltimea value buffer
Returns
json value coerced to time

◆ compare()

int Json_wrapper::compare ( const Json_wrapper other,
const CHARSET_INFO cs = nullptr 
) const

Compare this JSON value to another JSON value.

Parameters
[in]otherthe other JSON value
[in]csif given, this charset will be used in comparison of string values
Return values
-1if this JSON value is less than the other JSON value
0if the two JSON values are equal
1if this JSON value is greater than the other JSON value

◆ dbug_print()

void Json_wrapper::dbug_print ( const char *  message,
const JsonErrorHandler depth_handler 
) const

Print this JSON document to the debug trace.

Parameters
[in]messageIf given, the JSON document is prefixed with this message.

◆ empty()

bool Json_wrapper::empty ( ) const
inline

A Wrapper is defined to be empty if it is passed a NULL value with the constructor for JSON dom, or if the default constructor is used.

Returns
true if the wrapper is empty.

◆ field_type()

enum_field_types Json_wrapper::field_type ( ) const

Return the MYSQL type of the opaque value, see type().

Valid for J_OPAQUE. Calling this method if the type is not J_OPAQUE will give undefined results.

Returns
the type

◆ get_binary_value()

const json_binary::Value & Json_wrapper::get_binary_value ( ) const
inline

Gets the wrapped json_binary::Value object, if this wrapper holds a binary JSON value.

If is_dom() returns true, the result of calling this function is undefined.

◆ get_boolean()

bool Json_wrapper::get_boolean ( ) const

Get a boolean value (a JSON true or false literal).

Valid for J_BOOLEAN. Calling this method if the type is not J_BOOLEAN will give undefined results.

Returns
the value

◆ get_data()

const char * Json_wrapper::get_data ( ) const

Get a pointer to the data of a JSON string or JSON opaque value.

The data is still owner by the wrapper. The data may not be null terminated, so use in conjunction with get_data_length. Valid for J_STRING and J_OPAQUE. Calling this method if the type is not one of those will give undefined results.

Returns
the pointer

◆ get_data_length()

size_t Json_wrapper::get_data_length ( ) const

Get the length to the data of a JSON string or JSON opaque value.

Valid for J_STRING and J_OPAQUE. Calling this method if the type is not one of those will give undefined results.

Returns
the length

◆ get_datetime()

void Json_wrapper::get_datetime ( MYSQL_TIME t) const

Get the value of a JSON date/time value.

Valid for J_TIME, J_DATETIME, J_DATE and J_TIMESTAMP. Calling this method if the type is not one of those will give undefined results.

Parameters
[out]tthe date/time value

◆ get_datetime_packed()

const char * Json_wrapper::get_datetime_packed ( char *  buffer) const

Get the wrapped datetime value in the packed format.

Parameters
[in,out]buffera char buffer with space for at least Json_datetime::PACKED_SIZE characters
Returns
a char buffer that contains the packed representation of the datetime (may or may not be the same as buffer)

◆ get_decimal_data()

bool Json_wrapper::get_decimal_data ( my_decimal d) const

Get the MySQL representation of a JSON decimal value.

Valid for J_DECIMAL. Calling this method if the type is not J_DECIMAL will give undefined results.

Parameters
[out]dthe decimal value
Returns
false on success, true on failure (which would indicate an internal error)

◆ get_dom()

const Json_dom * Json_wrapper::get_dom ( ) const
inline

Gets a pointer to the wrapped Json_dom object, if this wrapper holds a DOM.

If is_dom() returns false, the result of calling this function is undefined.

◆ get_double()

double Json_wrapper::get_double ( ) const

Get the value of a JSON double number.

Valid for J_DOUBLE. Calling this method if the type is not J_DOUBLE will give undefined results.

Returns
the value

◆ get_free_space()

bool Json_wrapper::get_free_space ( const JsonSerializationErrorHandler error_handler,
size_t *  space 
) const

Calculate the amount of unused space inside a JSON binary value.

Parameters
[in]error_handlerthe handler that is invoked if an error occurs
[out]spacethe amount of unused space, or zero if this is a DOM
Returns
false on success
true if the JSON binary value was invalid

◆ get_int()

longlong Json_wrapper::get_int ( ) const

Get the value of a JSON signed integer number.

Valid for J_INT. Calling this method if the type is not J_INT will give undefined results.

Returns
the value

◆ get_uint()

ulonglong Json_wrapper::get_uint ( ) const

Get the value of a JSON unsigned integer number.

Valid for J_UINT. Calling this method if the type is not J_UINT will give undefined results.

Returns
the value

◆ is_binary_backed_by()

bool Json_wrapper::is_binary_backed_by ( const String str) const
inline

Check if the wrapped JSON document is a binary value (a json_binary::Value), and if that binary is pointing to data stored in the given string.

This function can be used to check if overwriting the data in the string might overwrite and corrupt the document contained in this wrapper.

Parameters
stra string which contains JSON binary data
Return values
trueif the string contains data that the wrapped document points to from its json_binary::Value representation
falseotherwise

◆ is_dom()

bool Json_wrapper::is_dom ( ) const
inline

Does this wrapper contain a DOM?

Return values
trueif the wrapper contains a DOM representation
falseif the wrapper contains a binary representation

◆ length()

size_t Json_wrapper::length ( ) const

Compute the length of a document.

This is the value which would be returned by the JSON_LENGTH() system function. So, this returns

  • for scalar values: 1
  • for objects: the number of members
  • for arrays: the number of cells
Returns
1, the number of members, or the number of cells

◆ lookup()

Json_wrapper Json_wrapper::lookup ( const MYSQL_LEX_CSTRING key) const

If this wrapper holds a JSON object, get the value corresponding to the member key.

Valid for J_OBJECT. Calling this method if the type is not J_OBJECT will give undefined results.

Parameters
[in]keyname for identifying member
Returns
The member value. If there is no member with the specified name, a value with type Json_dom::J_ERROR is returned.

◆ make_hash_key()

ulonglong Json_wrapper::make_hash_key ( ulonglong  hash_val) const

Make a hash key that can be used by sql_executor.cc/unique_hash in order to support SELECT DISTINCT.

Parameters
[in]hash_valAn initial hash value.

◆ make_sort_key()

size_t Json_wrapper::make_sort_key ( uchar to,
size_t  length 
) const

Make a sort key that can be used by filesort to order JSON values.

Parameters
[out]toa buffer to which the sort key is written
[in]lengththe length of the sort key

Key storage format is following:

  |<json type><   sort key    >|
   1 byte    / variable length /

JSON is assumed to be non-sql-null and valid (checked by caller). Key length contains full length - the len prefix itself, json type and the sort key. All numeric types are stored as a number, without distinction to double/decimal/int/etc. See make_json_numeric_sort_key(). Same is done to DATETIME and TIMESTAMP types. For string and opaque types only the prefix that fits into the output buffer is stored. For JSON objects and arrays only their length (number of elements) is stored, this is a limitation of current implementation.

◆ operator=() [1/2]

Json_wrapper & Json_wrapper::operator= ( const Json_wrapper old)

Assignment operator.

Does a deep copy of any owned DOM. If a DOM os not owned (aliased), the copy will also be aliased. Any owned DOM in the left side will be deallocated.

◆ operator=() [2/2]

Json_wrapper & Json_wrapper::operator= ( Json_wrapper &&  old)
noexcept

Move-assignment operator.

Take over the ownership of the other wrapper's DOM, unless it's aliased. If the other wrapper is aliased, this wrapper becomes an alias too. Any already owned DOM will be deallocated.

Parameters
oldthe wrapper whose contents to take over

◆ operator[]()

Json_wrapper Json_wrapper::operator[] ( size_t  index) const

If this wrapper holds a JSON array, get an array value by indexing into the array.

Valid for J_ARRAY. Calling this method if the type is not J_ARRAY will give undefined results.

Returns
the array value

◆ remove_duplicates()

void Json_wrapper::remove_duplicates ( const CHARSET_INFO cs = nullptr)

Remove duplicate values.

Applicable to JSON arrays only, array will be sorted.

◆ seek()

bool Json_wrapper::seek ( const Json_seekable_path path,
size_t  legs,
Json_wrapper_vector hits,
bool  auto_wrap,
bool  only_need_one 
)

Finds all of the json sub-documents which match the path expression.

Puts the matches on an evolving vector of results. This is a bit inefficient for binary wrappers because you can't build up a binary array incrementally from its cells. Instead, you have to turn each cell into a dom and then add the doms to a dom array.

Calling this if empty() returns true is an error.

Special care must be taken when the path expression contains more than one ellipsis (**) token. That is because multiple paths with ellipses may identify the same value. Consider the following document:

{ "a": { "x" : { "b": { "y": { "b": { "z": { "c": 100 } } } } } } }

The innermost value (the number 100) has the following unique, non-wildcarded address:

$.a.x.b.y.b.z.c

That location is reached by both of the following paths which include the ellipsis token:

$.a.x.b**.c
$.a.x.b.y.b**.c

And those addresses both satisfy the following path expression which has two ellipses:

$.a**.b**.c

In this case, we only want to return one instance of $.a.x.b.y.b.z.c

Similarly, special care must be taken if an auto-wrapping array path leg follows an ellipsis. Consider the following document:

{ "a": { "b" : [ 1, 2, 3 ] } }

The first element of the array (the number 1) can be reached with either of these two non-wildcarded addresses, due to array auto-wrapping:

$.a.b[0]
$.a.b[0][0]

Both of those addresses match the following path expression, which has an ellipsis followed by an auto-wrapping path leg:

$**[0]
Parameters
[in]paththe (possibly wildcarded) address of the sub-documents
[in]legsthe number of legs to use from path
[out]hitsthe result of the search
[in]auto_wraptrue of we match a final scalar with search for [0]
[in]only_need_oneTrue if we can stop after finding one match
Return values
falseon success
trueon error

◆ set_alias()

void Json_wrapper::set_alias ( )
inline

Only meaningful iff the wrapper encapsulates a DOM.

Marks the wrapper as not owning the DOM object, i.e. it will not be deallocated in the wrapper's destructor. Useful if one wants a wrapper around a DOM owned by someone else.

◆ sort()

void Json_wrapper::sort ( const CHARSET_INFO cs = nullptr)

Sort contents.

Applicable to JSON arrays only.

◆ to_binary()

bool Json_wrapper::to_binary ( const JsonSerializationErrorHandler error_handler,
String str 
) const

Get the wrapped contents in binary value form.

Parameters
error_handlera handler that is invoked if an error occurs
[in,out]stra string that will be filled with the binary value
Return values
falseon success
trueon error

◆ to_dom()

Json_dom * Json_wrapper::to_dom ( )

Get the wrapped contents in DOM form.

The DOM is (still) owned by the wrapper. If this wrapper originally held a value, it is now converted to hold (and eventually release) the DOM version.

Returns
pointer to a DOM object, or NULL if the DOM could not be allocated

◆ to_pretty_string()

bool Json_wrapper::to_pretty_string ( String buffer,
const char *  func_name,
const JsonErrorHandler depth_handler 
) const

Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646.

Add newlines and indentation for readability.

Parameters
[in,out]bufferthe buffer that receives the formatted string (the string is appended, so make sure the length is set correctly before calling)
[in]func_namethe name of the calling function
Return values
falseon success
trueon error

◆ to_string()

bool Json_wrapper::to_string ( String buffer,
bool  json_quoted,
const char *  func_name,
const JsonErrorHandler depth_handler 
) const

Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646.

Parameters
[in,out]bufferthe formatted string is appended, so make sure the length is set correctly before calling
[in]json_quotedif the JSON value is a string and json_quoted is false, don't perform quoting on the string. This is only used by JSON_UNQUOTE.
[in]func_nameThe name of the function that called to_string().
Returns
false formatting went well, else true

◆ type()

enum_json_type Json_wrapper::type ( ) const

Return the type of the wrapped JSON value.

Returns
the type, or Json_dom::J_ERROR if the wrapper does not contain a JSON value

Member Data Documentation

◆ 

union { ... } Json_wrapper::@38

◆ m_alias

bool Json_wrapper::m_alias

If true, don't deallocate m_dom_value in destructor.

◆ 

struct { ... } Json_wrapper::m_dom

The DOM representation, only used if m_is_dom is true.

◆ m_is_dom

bool Json_wrapper::m_is_dom
private

Wraps a DOM iff true.

◆ m_value [1/2]

Json_dom* Json_wrapper::m_value

◆ m_value [2/2]

json_binary::Value Json_wrapper::m_value

The binary representation, only used if m_is_dom is false.


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