yyjson 0.5.0
A high performance C JSON library.
|
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
#include <string.h>
#include <float.h>
Data Structures | |
struct | yyjson_alc |
struct | yyjson_read_err |
struct | yyjson_write_err |
union | yyjson_val_uni |
struct | yyjson_val |
struct | yyjson_doc |
struct | yyjson_arr_iter |
struct | yyjson_obj_iter |
struct | yyjson_mut_val |
struct | yyjson_str_chunk |
struct | yyjson_str_pool |
struct | yyjson_val_chunk |
struct | yyjson_val_pool |
struct | yyjson_mut_doc |
struct | yyjson_mut_arr_iter |
struct | yyjson_mut_obj_iter |
Macros | |
#define | YYJSON_MSC_VER 0 |
#define | YYJSON_GCC_VER 0 |
#define | YYJSON_STDC_VER 0 |
#define | YYJSON_CPP_VER 0 |
#define | yyjson_has_builtin(x) 0 |
#define | yyjson_has_attribute(x) 0 |
#define | yyjson_has_include(x) 0 |
#define | yyjson_inline |
#define | yyjson_noinline |
#define | yyjson_align(x) |
#define | yyjson_likely(expr) (expr) |
#define | yyjson_unlikely(expr) (expr) |
#define | yyjson_api |
#define | yyjson_api_inline static yyjson_inline |
#define | __bool_true_false_are_defined 1 |
#define | YYJSON_VERSION_MAJOR 0 |
#define | YYJSON_VERSION_MINOR 5 |
#define | YYJSON_VERSION_PATCH 0 |
#define | YYJSON_VERSION_HEX 0x000500 |
#define | YYJSON_VERSION_STRING "0.5.0" |
#define | YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ |
#define | YYJSON_PADDING_SIZE 4 |
#define | yyjson_arr_foreach(arr, idx, max, val) |
#define | yyjson_obj_foreach(obj, idx, max, key, val) |
#define | yyjson_mut_arr_foreach(arr, idx, max, val) |
#define | yyjson_mut_obj_foreach(obj, idx, max, key, val) |
Typedefs | |
typedef uint8_t | yyjson_type |
typedef uint8_t | yyjson_subtype |
typedef uint32_t | yyjson_read_flag |
typedef uint32_t | yyjson_read_code |
typedef uint32_t | yyjson_write_flag |
typedef uint32_t | yyjson_write_code |
struct yyjson_read_err |
Error information for JSON reader.
Data Fields | ||
---|---|---|
yyjson_read_code | code |
Error code, see |
const char * | msg |
Error message, constant, no need to free (NULL if success). |
size_t | pos |
Error byte position for input data (0 if success). |
struct yyjson_write_err |
Error information for JSON writer.
Data Fields | ||
---|---|---|
yyjson_write_code | code |
Error code, see |
const char * | msg |
Error message, constant, no need to free (NULL if success). |
union yyjson_val_uni |
Payload of a JSON value (8 bytes).
struct yyjson_val |
Immutable JSON value, 16 bytes.
An immutable value for reading JSON. A JSON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone.
Data Fields | ||
---|---|---|
uint64_t | tag |
type, subtype and length |
yyjson_val_uni | uni |
payload |
struct yyjson_doc |
An immutable document for reading JSON. This document holds memory for all its JSON values and strings. When it is no longer used, the user should call yyjson_doc_free() to free its memory.
Data Fields | ||
---|---|---|
yyjson_alc | alc |
Allocator used by document (nonnull). |
size_t | dat_read |
The total number of bytes read when parsing JSON (nonzero). |
yyjson_val * | root |
Root value of the document (nonnull). |
char * | str_pool |
The string pool used by JSON values (nullable). |
size_t | val_read |
The total number of value read when parsing JSON (nonzero). |
struct yyjson_arr_iter |
A JSON array iterator.
Data Fields | ||
---|---|---|
yyjson_val * | cur |
current value |
size_t | idx |
current index, from 0 |
size_t | max |
maximum index, idx < max |
struct yyjson_obj_iter |
A JSON object iterator.
If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:
Data Fields | ||
---|---|---|
yyjson_val * | cur |
current key |
size_t | idx |
current key index, from 0 |
size_t | max |
maximum key index, idx < max |
yyjson_val * | obj |
the object being iterated |
struct yyjson_mut_val |
Mutable JSON value, 24 bytes. The 'tag' and 'uni' field is same as immutable value. The 'next' field links all elements inside the container to be a cycle.
A mutable value for building JSON. A JSON Value has the same lifetime as its document. The memory is held by its document and and cannot be freed alone.
Data Fields | ||
---|---|---|
yyjson_mut_val * | next |
the next value in circular linked list |
uint64_t | tag |
type, subtype and length |
yyjson_val_uni | uni |
payload |
struct yyjson_str_chunk |
A memory chunk in string memory pool.
struct yyjson_str_pool |
A memory pool to hold all strings in a mutable document.
struct yyjson_val_chunk |
A memory chunk in value memory pool.
struct yyjson_val_pool |
A memory pool to hold all values in a mutable document.
struct yyjson_mut_doc |
A mutable document for building JSON. This document holds memory for all its JSON values and strings. When it is no longer used, the user should call yyjson_mut_doc_free() to free its memory.
Data Fields | ||
---|---|---|
yyjson_alc | alc |
a valid allocator, nonnull |
yyjson_mut_val * | root |
root value of the JSON document, nullable |
yyjson_str_pool | str_pool |
string memory pool |
yyjson_val_pool | val_pool |
value memory pool |
struct yyjson_mut_arr_iter |
A mutable JSON array iterator.
Data Fields | ||
---|---|---|
yyjson_mut_val * | arr |
the array being iterated |
yyjson_mut_val * | cur |
current value |
size_t | idx |
current index, from 0 |
size_t | max |
maximum index, idx < max |
yyjson_mut_val * | pre |
previous value |
struct yyjson_mut_obj_iter |
A mutable JSON object iterator.
If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:
Data Fields | ||
---|---|---|
yyjson_mut_val * | cur |
current key |
size_t | idx |
current key index, from 0 |
size_t | max |
maximum key index, idx < max |
yyjson_mut_val * | obj |
the object being iterated |
yyjson_mut_val * | pre |
previous key |
#define __bool_true_false_are_defined 1 |
stdint (C89 compatible) stdbool (C89 compatible)
#define yyjson_align | ( | x | ) |
align for compiler
#define yyjson_api |
function export
#define yyjson_api_inline static yyjson_inline |
inline function export
#define yyjson_arr_foreach | ( | arr, | |
idx, | |||
max, | |||
val | |||
) |
Macro for iterating over an array. It works like iterator, but with a more intuitive API.
#define YYJSON_CPP_VER 0 |
C++ version
#define YYJSON_GCC_VER 0 |
compiler version (GCC)
#define yyjson_has_attribute | ( | x | ) | 0 |
compiler attribute check (since gcc 5.0, clang 2.9, icc 17)
#define yyjson_has_builtin | ( | x | ) | 0 |
compiler builtin check (since gcc 10.0, clang 2.6, icc 2021)
#define yyjson_has_include | ( | x | ) | 0 |
include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3)
#define yyjson_inline |
inline for compiler
#define yyjson_likely | ( | expr | ) | (expr) |
likely for compiler
#define YYJSON_MSC_VER 0 |
compiler version (MSVC)
#define yyjson_mut_arr_foreach | ( | arr, | |
idx, | |||
max, | |||
val | |||
) |
Macro for iterating over an array. It works like iterator, but with a more intuitive API.
#define yyjson_mut_obj_foreach | ( | obj, | |
idx, | |||
max, | |||
key, | |||
val | |||
) |
Macro for iterating over an object. It works like iterator, but with a more intuitive API.
#define yyjson_noinline |
noinline for compiler
#define yyjson_obj_foreach | ( | obj, | |
idx, | |||
max, | |||
key, | |||
val | |||
) |
Macro for iterating over an object. It works like iterator, but with a more intuitive API.
#define YYJSON_PADDING_SIZE 4 |
Padding size for JSON reader.
#define YYJSON_STDC_VER 0 |
C version (STDC)
#define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ |
Mask and bits of JSON value.
#define yyjson_unlikely | ( | expr | ) | (expr) |
unlikely for compiler
#define YYJSON_VERSION_HEX 0x000500 |
The version of yyjson in hex: (major << 16) | (minor << 8) | (patch).
#define YYJSON_VERSION_MAJOR 0 |
char bit check The major version of yyjson.
#define YYJSON_VERSION_MINOR 5 |
The minor version of yyjson.
#define YYJSON_VERSION_PATCH 0 |
The patch version of yyjson.
#define YYJSON_VERSION_STRING "0.5.0" |
The version string of yyjson.
typedef uint32_t yyjson_read_code |
Result code for JSON reader.
typedef uint32_t yyjson_read_flag |
Run-time options for JSON reader.
typedef uint8_t yyjson_subtype |
Subtype of JSON value (2 bit).
typedef uint8_t yyjson_type |
Type of JSON value (3 bit).
typedef uint32_t yyjson_write_code |
Result code for JSON writer
typedef uint32_t yyjson_write_flag |
Run-time options for JSON writer.
yyjson_api bool yyjson_alc_pool_init | ( | yyjson_alc * | alc, |
void * | buf, | ||
size_t | size | ||
) |
A pool allocator uses fixed length pre-allocated memory.
This allocator may used to avoid malloc()/memmove() calls. The pre-allocated memory should be held by the caller. The upper limit of memory required to read JSON can be calculated using the yyjson_read_max_memory_usage() function, but the memory required to write JSON cannot be calculated directly.
This is not a general-purpose allocator, and should only be used to read or write single JSON document.
alc | The allocator to be initialized. If this parameter is NULL, the function will fail and return false. If buf or size is invalid, this parameter is left unmodified. |
buf | The buffer memory for this allocator. If this parameter is NULL, the function will fail and return false. |
size | The size of buf , in bytes. If this parameter is less than 8 words (32/64 bytes on 32/64-bit OS), the function will fail and return false. |
alc
has been successfully initialized.yyjson_api_inline yyjson_val * yyjson_arr_get | ( | yyjson_val * | arr, |
size_t | idx | ||
) |
Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds.
yyjson_api_inline yyjson_val * yyjson_arr_get_first | ( | yyjson_val * | arr | ) |
Returns the first element of this array. Returns NULL if arr
is NULL/empty or type is not array.
yyjson_api_inline yyjson_val * yyjson_arr_get_last | ( | yyjson_val * | arr | ) |
Returns the last element of this array. Returns NULL if arr
is NULL/empty or type is not array.
yyjson_api_inline bool yyjson_arr_iter_has_next | ( | yyjson_arr_iter * | iter | ) |
Returns whether the iteration has more elements. If iter
is NULL, this function will return false.
yyjson_api_inline bool yyjson_arr_iter_init | ( | yyjson_val * | arr, |
yyjson_arr_iter * | iter | ||
) |
Initialize an iterator for this array.
arr | The array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty. |
iter | The iterator to be initialized. If this parameter is NULL, the function will fail and return false. |
iter
has been successfully initialized.yyjson_api_inline yyjson_val * yyjson_arr_iter_next | ( | yyjson_arr_iter * | iter | ) |
Returns the next element in the iteration, or NULL on end. If iter
is NULL, this function will return NULL.
yyjson_api_inline size_t yyjson_arr_size | ( | yyjson_val * | arr | ) |
Returns the number of elements in this array. Returns 0 if arr
is NULL or type is not array.
yyjson_api_inline void yyjson_doc_free | ( | yyjson_doc * | doc | ) |
Release the JSON document and free the memory. After calling this function, the doc
and all values from the doc
are no longer available. This function will do nothing if the doc
is NULL.
yyjson_api_inline yyjson_val * yyjson_doc_get_pointer | ( | yyjson_doc * | doc, |
const char * | ptr | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a null-terminated UTF-8 string.
Returns NULL if there's no matched value.
yyjson_api_inline yyjson_val * yyjson_doc_get_pointern | ( | yyjson_doc * | doc, |
const char * | ptr, | ||
size_t | len | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the ptr
, in bytes.
Returns NULL if there's no matched value.
yyjson_api_inline size_t yyjson_doc_get_read_size | ( | yyjson_doc * | doc | ) |
Returns read size of input JSON data. Returns 0 if doc
is NULL. For example: the read size of "[1,2,3]" is 7 bytes.
yyjson_api_inline yyjson_val * yyjson_doc_get_root | ( | yyjson_doc * | doc | ) |
Returns the root value of this JSON document. Returns NULL if doc
is NULL.
yyjson_api_inline size_t yyjson_doc_get_val_count | ( | yyjson_doc * | doc | ) |
Returns total value count in this JSON document. Returns 0 if doc
is NULL. For example: the value count of "[1,2,3]" is 4.
yyjson_api yyjson_mut_doc * yyjson_doc_mut_copy | ( | yyjson_doc * | doc, |
const yyjson_alc * | alc | ||
) |
Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy
on the immutable document. If allocator is NULL, the default allocator will be used.
yyjson_api_inline bool yyjson_equals | ( | yyjson_val * | lhs, |
yyjson_val * | rhs | ||
) |
Returns whether two JSON values are equal (deep compare). Returns false if input is NULL.
yyjson_api_inline bool yyjson_equals_str | ( | yyjson_val * | val, |
const char * | str | ||
) |
Returns whether the JSON value is equals to a string. Returns false if input is NULL or type is not string.
yyjson_api_inline bool yyjson_equals_strn | ( | yyjson_val * | val, |
const char * | str, | ||
size_t | len | ||
) |
Returns whether the JSON value is equals to a string. The str
should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string.
yyjson_api_inline bool yyjson_get_bool | ( | yyjson_val * | val | ) |
Returns the content if the value is bool. Returns NULL if val
is NULL or type is not bool.
yyjson_api_inline int yyjson_get_int | ( | yyjson_val * | val | ) |
Returns the content and cast to int. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline size_t yyjson_get_len | ( | yyjson_val * | val | ) |
Returns the content length (string length, array size, object size. Returns 0 if val
is NULL or type is not string/array/object.
yyjson_api_inline yyjson_val * yyjson_get_pointer | ( | yyjson_val * | val, |
const char * | ptr | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a null-terminated UTF-8 string.
Returns NULL if there's no matched value. Returns NULL if val/ptr
is NULL or val
is not object.
yyjson_api_inline yyjson_val * yyjson_get_pointern | ( | yyjson_val * | val, |
const char * | ptr, | ||
size_t | len | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the ptr
, in bytes.
Returns NULL if there's no matched value. Returns NULL if val/ptr
is NULL or val
is not object.
yyjson_api_inline const char * yyjson_get_raw | ( | yyjson_val * | val | ) |
Returns the content if the value is raw. Returns NULL if val
is NULL or type is not raw.
yyjson_api_inline double yyjson_get_real | ( | yyjson_val * | val | ) |
Returns the content if the value is real number, or 0.0 on error. Returns 0.0 if val
is NULL or type is not real(double).
yyjson_api_inline int64_t yyjson_get_sint | ( | yyjson_val * | val | ) |
Returns the content and cast to int64_t. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline const char * yyjson_get_str | ( | yyjson_val * | val | ) |
Returns the content if the value is string. Returns NULL if val
is NULL or type is not string.
yyjson_api_inline yyjson_subtype yyjson_get_subtype | ( | yyjson_val * | val | ) |
Returns the JSON value's subtype. Returns YYJSON_SUBTYPE_NONE if val
is NULL.
yyjson_api_inline uint8_t yyjson_get_tag | ( | yyjson_val * | val | ) |
Returns the JSON value's tag. Returns 0 if val
is NULL.
yyjson_api_inline yyjson_type yyjson_get_type | ( | yyjson_val * | val | ) |
Returns the JSON value's type. Returns YYJSON_TYPE_NONE if val
is NULL.
yyjson_api_inline const char * yyjson_get_type_desc | ( | yyjson_val * | val | ) |
Returns the JSON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown".
yyjson_api_inline uint64_t yyjson_get_uint | ( | yyjson_val * | val | ) |
Returns the content and cast to uint64_t. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline bool yyjson_is_arr | ( | yyjson_val * | val | ) |
Returns whether the JSON value is array. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_bool | ( | yyjson_val * | val | ) |
Returns whether the JSON value is bool (true/false). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_ctn | ( | yyjson_val * | val | ) |
Returns whether the JSON value is container (array/object). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_false | ( | yyjson_val * | val | ) |
Returns whether the JSON value is false
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_int | ( | yyjson_val * | val | ) |
Returns whether the JSON value is integer (uint64_t/int64_t). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_null | ( | yyjson_val * | val | ) |
Returns whether the JSON value is null
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_num | ( | yyjson_val * | val | ) |
Returns whether the JSON value is number (uint64_t/int64_t/double). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_obj | ( | yyjson_val * | val | ) |
Returns whether the JSON value is object. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_raw | ( | yyjson_val * | val | ) |
Returns whether the JSON value is raw. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_real | ( | yyjson_val * | val | ) |
Returns whether the JSON value is real number (double). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_sint | ( | yyjson_val * | val | ) |
Returns whether the JSON value is signed integer (int64_t). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_str | ( | yyjson_val * | val | ) |
Returns whether the JSON value is string. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_true | ( | yyjson_val * | val | ) |
Returns whether the JSON value is true
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_is_uint | ( | yyjson_val * | val | ) |
Returns whether the JSON value is unsigned integer (uint64_t). Returns false if val
is NULL.
yyjson_api yyjson_mut_val * yyjson_merge_patch | ( | yyjson_mut_doc * | doc, |
yyjson_val * | orig, | ||
yyjson_val * | patch | ||
) |
Creates and returns a merge-patched JSON value (RFC 7386). The memory of the returned value is allocated by the doc
. Returns NULL if the patch could not be applied.
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr | ( | yyjson_mut_doc * | doc | ) |
Creates and returns an empty mutable array.
doc | A mutable document, used for memory allocation only. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_add_arr | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr | ||
) |
Creates and adds a new array at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
yyjson_api_inline bool yyjson_mut_arr_add_bool | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
bool | val | ||
) |
Adds a bool value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
val | The bool value to be added. |
yyjson_api_inline bool yyjson_mut_arr_add_false | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr | ||
) |
Adds a false
value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
yyjson_api_inline bool yyjson_mut_arr_add_int | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
int64_t | num | ||
) |
Adds a integer value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
num | The number to be added. |
yyjson_api_inline bool yyjson_mut_arr_add_null | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr | ||
) |
Adds a null
value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_add_obj | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr | ||
) |
Creates and adds a new object at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
yyjson_api_inline bool yyjson_mut_arr_add_real | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
double | num | ||
) |
Adds a double value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
num | The number to be added. |
yyjson_api_inline bool yyjson_mut_arr_add_sint | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
int64_t | num | ||
) |
Adds a signed integer value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
num | The number to be added. |
yyjson_api_inline bool yyjson_mut_arr_add_str | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
const char * | str | ||
) |
Adds a string value at the end of the array (no copy).
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
str | A null-terminated UTF-8 string. |
yyjson_api_inline bool yyjson_mut_arr_add_strcpy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
const char * | str | ||
) |
Adds a string value at the end of the array (copied).
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
str | A null-terminated UTF-8 string. |
yyjson_api_inline bool yyjson_mut_arr_add_strn | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
const char * | str, | ||
size_t | len | ||
) |
Adds a string value at the end of the array (no copy).
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
str | A UTF-8 string, null-terminator is not required. |
len | The length of the string, in bytes. |
yyjson_api_inline bool yyjson_mut_arr_add_strncpy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
const char * | str, | ||
size_t | len | ||
) |
Adds a string value at the end of the array (copied).
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
str | A UTF-8 string, null-terminator is not required. |
len | The length of the string, in bytes. |
yyjson_api_inline bool yyjson_mut_arr_add_true | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr | ||
) |
Adds a true
value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
yyjson_api_inline bool yyjson_mut_arr_add_uint | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | arr, | ||
uint64_t | num | ||
) |
Adds an unsigned integer value at the end of the array.
doc | The doc is only used for memory allocation. |
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
num | The number to be added. |
yyjson_api_inline bool yyjson_mut_arr_add_val | ( | yyjson_mut_val * | arr, |
yyjson_mut_val * | val | ||
) |
Adds a value at the end of the array.
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
val | The value to be inserted. Returns false if it is NULL. |
yyjson_api_inline bool yyjson_mut_arr_append | ( | yyjson_mut_val * | arr, |
yyjson_mut_val * | val | ||
) |
Inserts a value at the end of the array.
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
val | The value to be inserted. Returns false if it is NULL. |
yyjson_api_inline bool yyjson_mut_arr_clear | ( | yyjson_mut_val * | arr | ) |
Removes all values in this array.
arr | The array from which all of the values are to be removed. Returns false if it is NULL or not an array. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_get | ( | yyjson_mut_val * | arr, |
size_t | idx | ||
) |
Returns the element at the specified position in this array. Returns NULL if array is NULL/empty or the index is out of bounds.
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_get_first | ( | yyjson_mut_val * | arr | ) |
Returns the first element of this array. Returns NULL if arr
is NULL/empty or type is not array.
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_get_last | ( | yyjson_mut_val * | arr | ) |
Returns the last element of this array. Returns NULL if arr
is NULL/empty or type is not array.
yyjson_api_inline bool yyjson_mut_arr_insert | ( | yyjson_mut_val * | arr, |
yyjson_mut_val * | val, | ||
size_t | idx | ||
) |
Inserts a value into an array at a given index.
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
val | The value to be inserted. Returns false if it is NULL. |
idx | The index to which to insert the new value. Returns false if the index is out of range. |
yyjson_api_inline bool yyjson_mut_arr_iter_has_next | ( | yyjson_mut_arr_iter * | iter | ) |
Returns whether the iteration has more elements. If iter
is NULL, this function will return false.
yyjson_api_inline bool yyjson_mut_arr_iter_init | ( | yyjson_mut_val * | arr, |
yyjson_mut_arr_iter * | iter | ||
) |
Initialize an iterator for this array.
arr | The array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty. |
iter | The iterator to be initialized. If this parameter is NULL, the function will fail and return false. |
iter
has been successfully initialized.yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_iter_next | ( | yyjson_mut_arr_iter * | iter | ) |
Returns the next element in the iteration, or NULL on end. If iter
is NULL, this function will return NULL.
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_iter_remove | ( | yyjson_mut_arr_iter * | iter | ) |
Removes and returns current element in the iteration. If iter
is NULL, this function will return NULL.
yyjson_api_inline bool yyjson_mut_arr_prepend | ( | yyjson_mut_val * | arr, |
yyjson_mut_val * | val | ||
) |
Inserts a value at the head of the array.
arr | The array to which the value is to be inserted. Returns false if it is NULL or not an array. |
val | The value to be inserted. Returns false if it is NULL. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove | ( | yyjson_mut_val * | arr, |
size_t | idx | ||
) |
Removes and returns a value at index.
arr | The array from which the value is to be removed. Returns false if it is NULL or not an array. |
idx | The index from which to remove the value. Returns false if the index is out of range. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove_first | ( | yyjson_mut_val * | arr | ) |
Removes and returns the first value in this array.
arr | The array from which the value is to be removed. Returns false if it is NULL or not an array. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove_last | ( | yyjson_mut_val * | arr | ) |
Removes and returns the last value in this array.
arr | The array from which the value is to be removed. Returns false if it is NULL or not an array. |
yyjson_api_inline bool yyjson_mut_arr_remove_range | ( | yyjson_mut_val * | arr, |
size_t | idx, | ||
size_t | len | ||
) |
Removes all values within a specified range in the array.
arr | The array from which the value is to be removed. Returns false if it is NULL or not an array. |
idx | The start index of the range (0 is the first). |
len | The number of items in the range (can be 0). |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_replace | ( | yyjson_mut_val * | arr, |
size_t | idx, | ||
yyjson_mut_val * | val | ||
) |
Replaces a value at index and returns old value.
arr | The array to which the value is to be replaced. Returns false if it is NULL or not an array. |
idx | The index to which to replace the value. Returns false if the index is out of range. |
val | The new value to replace. Returns false if it is NULL. |
yyjson_api_inline bool yyjson_mut_arr_rotate | ( | yyjson_mut_val * | arr, |
size_t | idx | ||
) |
Rotates values in this array for the given number of times. For example: [1,2,3,4,5] rotate 2 is [3,4,5,1,2].
arr | The array to be rotated. |
idx | Index (or times) to rotate. |
yyjson_api_inline size_t yyjson_mut_arr_size | ( | yyjson_mut_val * | arr | ) |
Returns the number of elements in this array. Returns 0 if arr
is NULL or type is not array.
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_bool | ( | yyjson_mut_doc * | doc, |
const bool * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given boolean values.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of boolean values. |
count | The value count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_double | ( | yyjson_mut_doc * | doc, |
const double * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given double numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of double numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_float | ( | yyjson_mut_doc * | doc, |
const float * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given float numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of float numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_real | ( | yyjson_mut_doc * | doc, |
const double * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given real numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of real numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint | ( | yyjson_mut_doc * | doc, |
const int64_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given sint numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of sint numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint16 | ( | yyjson_mut_doc * | doc, |
const int16_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given int16 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of int16 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint32 | ( | yyjson_mut_doc * | doc, |
const int32_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given int32 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of int32 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint64 | ( | yyjson_mut_doc * | doc, |
const int64_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given int64 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of int64 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint8 | ( | yyjson_mut_doc * | doc, |
const int8_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given int8 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of int8 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_str | ( | yyjson_mut_doc * | doc, |
const char ** | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given strings, these strings will not be copied.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL. |
count | The number of values in vals . If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_strcpy | ( | yyjson_mut_doc * | doc, |
const char ** | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given strings, these strings will be copied.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL. |
count | The number of values in vals . If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_strn | ( | yyjson_mut_doc * | doc, |
const char ** | vals, | ||
const size_t * | lens, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given strings and string lengths, these strings will not be copied.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL. |
lens | A C array of string lengths, in bytes. |
count | The number of strings in vals . If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_strncpy | ( | yyjson_mut_doc * | doc, |
const char ** | vals, | ||
const size_t * | lens, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given strings and string lengths, these strings will be copied.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL. |
lens | A C array of string lengths, in bytes. |
count | The number of strings in vals . If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint | ( | yyjson_mut_doc * | doc, |
const uint64_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given uint numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of uint numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint16 | ( | yyjson_mut_doc * | doc, |
const uint16_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given uint16 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of uint16 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint32 | ( | yyjson_mut_doc * | doc, |
const uint32_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given uint32 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of uint32 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint64 | ( | yyjson_mut_doc * | doc, |
const uint64_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given uint64 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of uint64 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint8 | ( | yyjson_mut_doc * | doc, |
const uint8_t * | vals, | ||
size_t | count | ||
) |
Creates and returns a new mutable array with the given uint8 numbers.
doc | A mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL. |
vals | A C array of uint8 numbers. |
count | The number count. If this value is 0, an empty array will return. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_bool | ( | yyjson_mut_doc * | doc, |
bool | val | ||
) |
Creates and returns a bool value, returns NULL on error.
yyjson_api void yyjson_mut_doc_free | ( | yyjson_mut_doc * | doc | ) |
Release the JSON document and free the memory. After calling this function, the doc
and all values from the doc
are no longer available. This function will do nothing if the doc
is NULL.
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_pointer | ( | yyjson_mut_doc * | doc, |
const char * | ptr | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a null-terminated UTF-8 string.
Returns NULL if there's no matched value.
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_pointern | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the ptr
, in bytes.
Returns NULL if there's no matched value.
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_root | ( | yyjson_mut_doc * | doc | ) |
Returns the root value of this JSON document. Returns NULL if doc
is NULL.
yyjson_api yyjson_mut_doc * yyjson_mut_doc_mut_copy | ( | yyjson_mut_doc * | doc, |
const yyjson_alc * | alc | ||
) |
Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy
on the mutable document. If allocator is NULL, the default allocator will be used.
yyjson_api yyjson_mut_doc * yyjson_mut_doc_new | ( | const yyjson_alc * | alc | ) |
Creates and returns a new mutable JSON document, returns NULL on error. If allocator is NULL, the default allocator will be used.
yyjson_api_inline void yyjson_mut_doc_set_root | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | root | ||
) |
Sets the root value of this JSON document. Pass NULL to clear root value of the document.
yyjson_api_inline bool yyjson_mut_equals | ( | yyjson_mut_val * | lhs, |
yyjson_mut_val * | rhs | ||
) |
Returns whether two JSON values are equal (deep compare). Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_equals_str | ( | yyjson_mut_val * | val, |
const char * | str | ||
) |
Returns whether the JSON value is equals to a string. The str
should be a null-terminated UTF-8 string. Returns false if input is NULL or type is not string.
yyjson_api_inline bool yyjson_mut_equals_strn | ( | yyjson_mut_val * | val, |
const char * | str, | ||
size_t | len | ||
) |
Returns whether the JSON value is equals to a string. The str
should be a UTF-8 string, null-terminator is not required. Returns false if input is NULL or type is not string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_false | ( | yyjson_mut_doc * | doc | ) |
Creates and returns a false value, returns NULL on error.
yyjson_api_inline bool yyjson_mut_get_bool | ( | yyjson_mut_val * | val | ) |
Returns the content if the value is bool. Returns NULL if val
is NULL or type is not bool.
yyjson_api_inline int yyjson_mut_get_int | ( | yyjson_mut_val * | val | ) |
Returns the content and cast to int. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline size_t yyjson_mut_get_len | ( | yyjson_mut_val * | val | ) |
Returns the content length (string length, array size, object size. Returns 0 if val
is NULL or type is not string/array/object.
yyjson_api_inline yyjson_mut_val * yyjson_mut_get_pointer | ( | yyjson_mut_val * | val, |
const char * | ptr | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a null-terminated UTF-8 string.
Returns NULL if there's no matched value.
yyjson_api_inline yyjson_mut_val * yyjson_mut_get_pointern | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len | ||
) |
Get a JSON value with JSON Pointer (RFC 6901). The ptr
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the ptr
, in bytes.
Returns NULL if there's no matched value.
yyjson_api_inline const char * yyjson_mut_get_raw | ( | yyjson_mut_val * | val | ) |
Returns the content if the value is raw. Returns NULL if val
is NULL or type is not raw.
yyjson_api_inline double yyjson_mut_get_real | ( | yyjson_mut_val * | val | ) |
Returns the content if the value is real number. Returns 0.0 if val
is NULL or type is not real(double).
yyjson_api_inline int64_t yyjson_mut_get_sint | ( | yyjson_mut_val * | val | ) |
Returns the content and cast to int64_t. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline const char * yyjson_mut_get_str | ( | yyjson_mut_val * | val | ) |
Returns the content if the value is string. Returns NULL if val
is NULL or type is not string.
yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype | ( | yyjson_mut_val * | val | ) |
Returns the JSON value's subtype. Returns YYJSON_SUBTYPE_NONE if val
is NULL.
yyjson_api_inline uint8_t yyjson_mut_get_tag | ( | yyjson_mut_val * | val | ) |
Returns the JSON value's tag. Returns 0 if val
is NULL.
yyjson_api_inline yyjson_type yyjson_mut_get_type | ( | yyjson_mut_val * | val | ) |
Returns the JSON value's type. Returns YYJSON_TYPE_NONE if val
is NULL.
yyjson_api_inline const char * yyjson_mut_get_type_desc | ( | yyjson_mut_val * | val | ) |
Returns the JSON value's type description. The return value should be one of these strings: "raw", "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown".
yyjson_api_inline uint64_t yyjson_mut_get_uint | ( | yyjson_mut_val * | val | ) |
Returns the content and cast to uint64_t. Returns 0 if val
is NULL or type is not integer(sint/uint).
yyjson_api_inline yyjson_mut_val * yyjson_mut_int | ( | yyjson_mut_doc * | doc, |
int64_t | num | ||
) |
Creates and returns a signed integer value, returns NULL on error.
yyjson_api_inline bool yyjson_mut_is_arr | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is array. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_bool | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is bool (true/false). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_ctn | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is container (array/object). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_false | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is false
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_int | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is integer (uint64_t/int64_t). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_null | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is null
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_num | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is number (uint/sint/real). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_obj | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is object. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_raw | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is raw. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_real | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is real number (double). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_sint | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is signed integer (int64_t). Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_str | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is string. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_true | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is true
. Returns false if val
is NULL.
yyjson_api_inline bool yyjson_mut_is_uint | ( | yyjson_mut_val * | val | ) |
Returns whether the JSON value is unsigned integer (uint64_t). Returns false if val
is NULL.
yyjson_api yyjson_mut_val * yyjson_mut_merge_patch | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | orig, | ||
yyjson_mut_val * | patch | ||
) |
Creates and returns a merge-patched JSON value (RFC 7386). The memory of the returned value is allocated by the doc
. Returns NULL if the patch could not be applied.
yyjson_api_inline yyjson_mut_val * yyjson_mut_null | ( | yyjson_mut_doc * | doc | ) |
Creates and returns a null value, returns NULL on error.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj | ( | yyjson_mut_doc * | doc | ) |
Creates and returns a mutable object, returns NULL on error.
yyjson_api_inline bool yyjson_mut_obj_add | ( | yyjson_mut_val * | obj, |
yyjson_mut_val * | key, | ||
yyjson_mut_val * | val | ||
) |
Adds a key-value pair at the end of the object. This function allows duplicated key in one object.
obj | The object to which the new key-value pair is to be added. |
key | The key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy(). |
val | The value to add to the object. |
yyjson_api_inline bool yyjson_mut_obj_add_bool | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
bool | val | ||
) |
Adds a bool value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_false | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key | ||
) |
Adds a false
value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_int | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
int64_t | val | ||
) |
Adds an int value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_null | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key | ||
) |
Adds a null
value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_real | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
double | val | ||
) |
Adds a double value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_sint | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
int64_t | val | ||
) |
Adds a signed integer value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_str | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
const char * | val | ||
) |
Adds a string value at the end of the object. The key
and val
should be null-terminated UTF-8 strings. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_strcpy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
const char * | val | ||
) |
Adds a string value at the end of the object. The key
and val
should be null-terminated UTF-8 strings. The value string is copied. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_strn | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
const char * | val, | ||
size_t | len | ||
) |
Adds a string value at the end of the object. The key
should be a null-terminated UTF-8 string. The val
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the val
, in bytes. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_strncpy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
const char * | val, | ||
size_t | len | ||
) |
Adds a string value at the end of the object. The key
should be a null-terminated UTF-8 string. The val
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the val
, in bytes. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_true | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key | ||
) |
Adds a true
value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_uint | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
uint64_t | val | ||
) |
Adds an unsigned integer value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_add_val | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
yyjson_mut_val * | val | ||
) |
Adds a JSON value at the end of the object. The key
should be a null-terminated UTF-8 string. This function allows duplicated key in one object.
yyjson_api_inline bool yyjson_mut_obj_clear | ( | yyjson_mut_val * | obj | ) |
Removes all key-value pairs in this object.
obj | The object from which all of the values are to be removed. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_get | ( | yyjson_mut_val * | obj, |
const char * | key | ||
) |
Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key
is NULL, or type is not object.
The key
should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_getn | ( | yyjson_mut_val * | obj, |
const char * | key, | ||
size_t | key_len | ||
) |
Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key
is NULL, or type is not object.
The key
should be a UTF-8 string, null-terminator is not required. The key_len
should be the length of the key, in bytes.
yyjson_api_inline bool yyjson_mut_obj_insert | ( | yyjson_mut_val * | obj, |
yyjson_mut_val * | key, | ||
yyjson_mut_val * | val, | ||
size_t | idx | ||
) |
Inserts a key-value pair to the object at the given position. This function allows duplicated key in one object.
obj | The object to which the new key-value pair is to be added. |
key | The key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy(). |
val | The value to add to the object. |
idx | The index to which to insert the new pair. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_get | ( | yyjson_mut_obj_iter * | iter, |
const char * | key | ||
) |
Iterates to a specified key and returns the value.
This function does the same thing as yyjson_mut_obj_get(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.
iter | The object iterator, should not be NULL. |
key | The key, should be a UTF-8 string with null-terminator. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_get_val | ( | yyjson_mut_val * | key | ) |
Returns the value for key inside the iteration. If iter
is NULL, this function will return NULL.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_getn | ( | yyjson_mut_obj_iter * | iter, |
const char * | key, | ||
size_t | key_len | ||
) |
Iterates to a specified key and returns the value.
This function does the same thing as yyjson_mut_obj_getn(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.
iter | The object iterator, should not be NULL. |
key | The key, should be a UTF-8 string, null-terminator is not required. |
key_len | The the length of key , in bytes. |
yyjson_api_inline bool yyjson_mut_obj_iter_has_next | ( | yyjson_mut_obj_iter * | iter | ) |
Returns whether the iteration has more elements. If iter
is NULL, this function will return false.
yyjson_api_inline bool yyjson_mut_obj_iter_init | ( | yyjson_mut_val * | obj, |
yyjson_mut_obj_iter * | iter | ||
) |
Initialize an iterator for this object.
obj | The object to be iterated over. If this parameter is NULL or not an array, iter will be set to empty. |
iter | The iterator to be initialized. If this parameter is NULL, the function will fail and return false. |
iter
has been successfully initialized.yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_next | ( | yyjson_mut_obj_iter * | iter | ) |
Returns the next key in the iteration, or NULL on end. If iter
is NULL, this function will return NULL.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_remove | ( | yyjson_mut_obj_iter * | iter | ) |
Removes and returns current key-value pair in the iteration. If iter
is NULL, this function will return NULL.
yyjson_api_inline bool yyjson_mut_obj_put | ( | yyjson_mut_val * | obj, |
yyjson_mut_val * | key, | ||
yyjson_mut_val * | val | ||
) |
Sets a key-value pair at the end of the object. This function may remove all key-value pairs for the given key before add.
obj | The object to which the new key-value pair is to be added. |
key | The key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy(). |
val | The value to add to the object. If this value is null, the behavior is same as yyjson_mut_obj_remove(). |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove | ( | yyjson_mut_val * | obj, |
yyjson_mut_val * | key | ||
) |
Removes all key-value pair from the object with given key.
obj | The object from which the key-value pair is to be removed. |
key | The key, should be a string value. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove_key | ( | yyjson_mut_val * | obj, |
const char * | key | ||
) |
Removes all key-value pair from the object with given key.
obj | The object from which the key-value pair is to be removed. |
key | The key, should be a UTF-8 string with null-terminator. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove_keyn | ( | yyjson_mut_val * | obj, |
const char * | key, | ||
size_t | key_len | ||
) |
Removes all key-value pair from the object with given key.
obj | The object from which the key-value pair is to be removed. |
key | The key, should be a UTF-8 string, null-terminator is not required. |
key_len | The length of the key. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove_str | ( | yyjson_mut_val * | obj, |
const char * | key | ||
) |
Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The key
should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove_strn | ( | yyjson_mut_val * | obj, |
const char * | key, | ||
size_t | len | ||
) |
Removes all key-value pairs for the given key. Returns the first value to which the specified key is mapped or NULL if this object contains no mapping for the key. The key
should be a UTF-8 string, null-terminator is not required. The len
should be the length of the key, in bytes.
yyjson_api_inline bool yyjson_mut_obj_replace | ( | yyjson_mut_val * | obj, |
yyjson_mut_val * | key, | ||
yyjson_mut_val * | val | ||
) |
Replaces value from the object with given key. If the key is not exist, or the value is NULL, it will fail.
obj | The object to which the value is to be replaced. |
key | The key, should be a string value. |
val | The value to replace into the object. |
yyjson_api_inline bool yyjson_mut_obj_rotate | ( | yyjson_mut_val * | obj, |
size_t | idx | ||
) |
Rotates key-value pairs in the object for the given number of times. For example: {"a":1,"b":2,"c":3,"d":4} rotate 1 is {"b":2,"c":3,"d":4,"a":1}.
obj | The object to be rotated. |
idx | Index (or times) to rotate. |
yyjson_api_inline size_t yyjson_mut_obj_size | ( | yyjson_mut_val * | obj | ) |
Returns the number of key-value pairs in this object. Returns 0 if obj
is NULL or type is not object.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_with_kv | ( | yyjson_mut_doc * | doc, |
const char ** | kv_pairs, | ||
size_t | pair_count | ||
) |
Creates and returns a mutable object with key-value pairs and pair count, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_with_str | ( | yyjson_mut_doc * | doc, |
const char ** | keys, | ||
const char ** | vals, | ||
size_t | count | ||
) |
Creates and returns a mutable object with keys and values, returns NULL on error. The keys and values are not copied. The strings should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_raw | ( | yyjson_mut_doc * | doc, |
const char * | str | ||
) |
Creates and returns a raw value, returns NULL on error. The str
should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_rawcpy | ( | yyjson_mut_doc * | doc, |
const char * | str | ||
) |
Creates and returns a raw value, returns NULL on error. The str
should be a null-terminated UTF-8 string. The input string is copied and held by the document.
yyjson_api_inline yyjson_mut_val * yyjson_mut_rawn | ( | yyjson_mut_doc * | doc, |
const char * | str, | ||
size_t | len | ||
) |
Creates and returns a raw value, returns NULL on error. The str
should be a UTF-8 string, null-terminator is not required.
yyjson_api_inline yyjson_mut_val * yyjson_mut_rawncpy | ( | yyjson_mut_doc * | doc, |
const char * | str, | ||
size_t | len | ||
) |
Creates and returns a raw value, returns NULL on error. The str
should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document.
yyjson_api_inline yyjson_mut_val * yyjson_mut_real | ( | yyjson_mut_doc * | doc, |
double | num | ||
) |
Creates and returns an real number value, returns NULL on error.
yyjson_api_inline yyjson_mut_val * yyjson_mut_sint | ( | yyjson_mut_doc * | doc, |
int64_t | num | ||
) |
Creates and returns a signed integer value, returns NULL on error.
yyjson_api_inline yyjson_mut_val * yyjson_mut_str | ( | yyjson_mut_doc * | doc, |
const char * | str | ||
) |
Creates and returns a string value, returns NULL on error. The str
should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_mut_val * yyjson_mut_strcpy | ( | yyjson_mut_doc * | doc, |
const char * | str | ||
) |
Creates and returns a string value, returns NULL on error. The str
should be a null-terminated UTF-8 string. The input string is copied and held by the document.
yyjson_api_inline yyjson_mut_val * yyjson_mut_strn | ( | yyjson_mut_doc * | doc, |
const char * | str, | ||
size_t | len | ||
) |
Creates and returns a string value, returns NULL on error. The str
should be a UTF-8 string, null-terminator is not required.
yyjson_api_inline yyjson_mut_val * yyjson_mut_strncpy | ( | yyjson_mut_doc * | doc, |
const char * | str, | ||
size_t | len | ||
) |
Creates and returns a string value, returns NULL on error. The str
should be a UTF-8 string, null-terminator is not required. The input string is copied and held by the document.
yyjson_api_inline yyjson_mut_val * yyjson_mut_true | ( | yyjson_mut_doc * | doc | ) |
Creates and returns a true value, returns NULL on error.
yyjson_api_inline yyjson_mut_val * yyjson_mut_uint | ( | yyjson_mut_doc * | doc, |
uint64_t | num | ||
) |
Creates and returns an unsigned integer value, returns NULL on error.
yyjson_api yyjson_mut_val * yyjson_mut_val_mut_copy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | val | ||
) |
Copies and return a new mutable value from input, returns NULL on error, This makes a deep-copy
on the mutable value. The memory was managed by mutable document.
yyjson_api_inline char * yyjson_mut_val_write | ( | const yyjson_mut_val * | val, |
yyjson_write_flag | flg, | ||
size_t * | len | ||
) |
Write a value to JSON string.
This function is thread-safe when: The val
is not is not modified by other threads.
val | The JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
yyjson_api bool yyjson_mut_val_write_file | ( | const char * | path, |
const yyjson_mut_val * | val, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a value to JSON file with options.
This function is thread-safe when:
val
is not modified by other threads.alc
is thread-safe or NULL.path | The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. |
val | The mutable JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api char * yyjson_mut_val_write_opts | ( | const yyjson_mut_val * | val, |
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
size_t * | len, | ||
yyjson_write_err * | err | ||
) |
Write a value to JSON string with options.
This function is thread-safe when:
val
is not modified by other threads.alc
is thread-safe or NULL.val | The mutable JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api_inline char * yyjson_mut_write | ( | const yyjson_mut_doc * | doc, |
yyjson_write_flag | flg, | ||
size_t * | len | ||
) |
Write a document to JSON string.
This function is thread-safe when: The doc
is not is not modified by other threads.
doc | The JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
yyjson_api bool yyjson_mut_write_file | ( | const char * | path, |
const yyjson_mut_doc * | doc, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a document to JSON file with options.
This function is thread-safe when:
doc
is not modified by other threads.alc
is thread-safe or NULL.path | The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. |
doc | The mutable JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api char * yyjson_mut_write_opts | ( | const yyjson_mut_doc * | doc, |
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
size_t * | len, | ||
yyjson_write_err * | err | ||
) |
Write a document to JSON string with options.
This function is thread-safe when:
doc
is not modified by other threads.alc
is thread-safe or NULL.doc | The mutable JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api_inline yyjson_val * yyjson_obj_get | ( | yyjson_val * | obj, |
const char * | key | ||
) |
Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key
is NULL, or type is not object.
The key
should be a null-terminated UTF-8 string.
yyjson_api_inline yyjson_val * yyjson_obj_getn | ( | yyjson_val * | obj, |
const char * | key, | ||
size_t | key_len | ||
) |
Returns the value to which the specified key is mapped. Returns NULL if this object contains no mapping for the key. Returns NULL if obj/key
is NULL, or type is not object.
The key
should be a UTF-8 string, null-terminator is not required. The key_len
should be the length of the key, in bytes.
yyjson_api_inline yyjson_val * yyjson_obj_iter_get | ( | yyjson_obj_iter * | iter, |
const char * | key | ||
) |
Iterates to a specified key and returns the value.
This function does the same thing as yyjson_obj_get(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.
iter | The object iterator, should not be NULL. |
key | The key, should be a UTF-8 string with null-terminator. |
yyjson_api_inline yyjson_val * yyjson_obj_iter_get_val | ( | yyjson_val * | key | ) |
Returns the value for key inside the iteration. If iter
is NULL, this function will return NULL.
yyjson_api_inline yyjson_val * yyjson_obj_iter_getn | ( | yyjson_obj_iter * | iter, |
const char * | key, | ||
size_t | key_len | ||
) |
Iterates to a specified key and returns the value.
This function does the same thing as yyjson_obj_getn(), but is much faster if the ordering of the keys is known at compile-time and you are using the same order to look up the values. If the key exists in this object, then the iterator will stop at the next key, otherwise the iterator will not change and NULL is returned.
iter | The object iterator, should not be NULL. |
key | The key, should be a UTF-8 string, null-terminator is not required. |
key_len | The the length of key , in bytes. |
yyjson_api_inline bool yyjson_obj_iter_has_next | ( | yyjson_obj_iter * | iter | ) |
Returns whether the iteration has more elements. If iter
is NULL, this function will return false.
yyjson_api_inline bool yyjson_obj_iter_init | ( | yyjson_val * | obj, |
yyjson_obj_iter * | iter | ||
) |
Initialize an iterator for this object.
obj | The object to be iterated over. If this parameter is NULL or not an object, iter will be set to empty. |
iter | The iterator to be initialized. If this parameter is NULL, the function will fail and return false. |
iter
has been successfully initialized.yyjson_api_inline yyjson_val * yyjson_obj_iter_next | ( | yyjson_obj_iter * | iter | ) |
Returns the next key in the iteration, or NULL on end. If iter
is NULL, this function will return NULL.
yyjson_api_inline size_t yyjson_obj_size | ( | yyjson_val * | obj | ) |
Returns the number of key-value pairs in this object. Returns 0 if obj
is NULL or type is not object.
yyjson_api_inline yyjson_doc * yyjson_read | ( | const char * | dat, |
size_t | len, | ||
yyjson_read_flag | flg | ||
) |
Read a JSON string.
This function is thread-safe.
dat | The JSON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. |
len | The length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL. |
flg | The JSON read options. Multiple options can be combined with | operator. 0 means no options. |
yyjson_api yyjson_doc * yyjson_read_file | ( | const char * | path, |
yyjson_read_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_read_err * | err | ||
) |
Read a JSON file.
This function is thread-safe when:
alc
is thread-safe or NULL.path | The JSON file's path. If this path is NULL or invalid, the function will fail and return NULL. |
flg | The JSON read options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api_inline size_t yyjson_read_max_memory_usage | ( | size_t | len, |
yyjson_read_flag | flg | ||
) |
Returns the size of maximum memory usage to read a JSON data.
You may use this value to avoid malloc() or calloc() call inside the reader to get better performance, or read multiple JSON with one piece of memory.
len | The length of JSON data in bytes. |
flg | The JSON read options. |
yyjson_api yyjson_doc * yyjson_read_opts | ( | char * | dat, |
size_t | len, | ||
yyjson_read_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_read_err * | err | ||
) |
Read JSON with options.
This function is thread-safe when:
dat
is not modified by other threads.alc
is thread-safe or NULL.dat | The JSON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL. The dat will not be modified without the flag YYJSON_READ_INSITU , so you can pass a const char * string and case it to char * if you don't use the YYJSON_READ_INSITU flag. |
len | The length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL. |
flg | The JSON read options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON reader. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api yyjson_mut_val * yyjson_val_mut_copy | ( | yyjson_mut_doc * | doc, |
yyjson_val * | val | ||
) |
Copies and returns a new mutable value from input, returns NULL on error. This makes a deep-copy
on the immutable value. The memory was managed by mutable document.
yyjson_api_inline char * yyjson_val_write | ( | const yyjson_val * | val, |
yyjson_write_flag | flg, | ||
size_t * | len | ||
) |
Write a value to JSON string.
This function is thread-safe.
val | The JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
yyjson_api bool yyjson_val_write_file | ( | const char * | path, |
const yyjson_val * | val, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a value to JSON file with options.
This function is thread-safe when:
alc
is thread-safe or NULL.path | The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. |
val | The JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api char * yyjson_val_write_opts | ( | const yyjson_val * | val, |
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
size_t * | len, | ||
yyjson_write_err * | err | ||
) |
Write a value to JSON string with options.
This function is thread-safe when: The alc
is thread-safe or NULL.
val | The JSON root value. If this parameter is NULL, the function will fail and return NULL. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api uint32_t yyjson_version | ( | void | ) |
The version of yyjson in hex, same as YYJSON_VERSION_HEX
.
yyjson_api_inline char * yyjson_write | ( | const yyjson_doc * | doc, |
yyjson_write_flag | flg, | ||
size_t * | len | ||
) |
Write a document to JSON string.
This function is thread-safe.
doc | The JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
yyjson_api bool yyjson_write_file | ( | const char * | path, |
const yyjson_doc * | doc, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a document to JSON file with options.
This function is thread-safe when:
alc
is thread-safe or NULL.path | The JSON file's path. If this path is NULL or invalid, the function will fail and return false. If this file is not empty, the content will be discarded. |
doc | The JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
yyjson_api char * yyjson_write_opts | ( | const yyjson_doc * | doc, |
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
size_t * | len, | ||
yyjson_write_err * | err | ||
) |
Write a document to JSON string with options.
This function is thread-safe when: The alc
is thread-safe or NULL.
doc | The JSON document. If this doc is NULL or has no root, the function will fail and return false. |
flg | The JSON write options. Multiple options can be combined with | operator. 0 means no options. |
alc | The memory allocator used by JSON writer. Pass NULL to use the libc's default allocator. |
len | A pointer to receive output length in bytes. Pass NULL if you don't need length information. |
err | A pointer to receive error information. Pass NULL if you don't need error information. |
|
static |
Allow C-style single line and multiple line comments (non-standard).
|
static |
Allow inf/nan number and literal, case-insensitive, such as 1e999, NaN, inf, -Infinity (non-standard).
|
static |
Allow reading invalid unicode when parsing string values (non-standard). Invalid characters will be allowed to appear in the string values, but invalid escape sequences will still be reported as errors. This flag does not affect the performance of correctly encoded strings.
|
static |
Allow single trailing comma at the end of an object or array, such as [1,2,3,] {"a":1,"b":2,} (non-standard).
|
static |
Input JSON string is empty.
|
static |
Failed to open a file.
|
static |
Failed to read a file.
|
static |
Invalid comment, such as unclosed multi-line comment.
|
static |
Invalid number, such as "123.e12", "000".
|
static |
Invalid parameter, such as NULL string or invalid file path.
|
static |
Invalid string, such as invalid escaped character inside a string.
|
static |
Invalid JSON structure, such as "[1,]".
|
static |
Invalid JSON literal, such as "truu".
|
static |
Memory allocation failure occurs.
|
static |
Unexpected character inside the document, such as "[#]".
|
static |
Unexpected content after document, such as "[1]#".
|
static |
Unexpected ending, such as "[123".
|
static |
Read the input data in-situ. This option allows the reader to modify and use input data to store string values, which can increase reading speed slightly. The caller should hold the input data before free the document. The input data must be padded by at least YYJSON_PADDING_SIZE
bytes. For example: "[1,2]" should be "[1,2]\0\0\0\0", length should be 5.
|
static |
Default option (RFC 8259 compliant):
|
static |
Read number as raw string (value with YYJSON_TYPE_RAW type), inf/nan literal is also read as raw with ALLOW_INF_AND_NAN
flag.
|
static |
Stop when done instead of issuing an error if there's additional content after a JSON document. This option may be used to parse small pieces of JSON in larger data, such as NDJSON
.
|
static |
Success, no error.
|
static |
Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard).
|
static |
Allow invalid unicode when encoding string values (non-standard). Invalid characters in string value will be copied byte by byte. If YYJSON_WRITE_ESCAPE_UNICODE
flag is also set, invalid character will be escaped as U+FFFD
(replacement character). This flag does not affect the performance of correctly encoded strings.
|
static |
Failed to open a file.
|
static |
Failed to write a file.
|
static |
Invalid parameter, such as NULL document.
|
static |
Invalid unicode in string.
|
static |
Invalid value type in JSON document.
|
static |
Memory allocation failure occurs.
|
static |
NaN or Infinity number occurs.
|
static |
Escape '/' as '\/'.
|
static |
Escape unicode as uXXXX
, make the output ASCII only.
|
static |
Write inf and nan number as null literal. This flag will override YYJSON_WRITE_ALLOW_INF_AND_NAN
flag.
|
static |
Default option:
|
static |
Write JSON pretty with 4 space indent.
|
static |
Success, no error.