yyjson 0.10.0
A high performance C JSON library.
|
#include <stdio.h>
#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 |
struct | yyjson_arr_iter |
struct | yyjson_obj_iter |
struct | yyjson_mut_arr_iter |
struct | yyjson_mut_obj_iter |
struct | yyjson_ptr_err |
struct | yyjson_ptr_ctx |
struct | yyjson_patch_err |
union | yyjson_val_uni |
struct | yyjson_val |
struct | yyjson_doc |
struct | yyjson_mut_val |
struct | yyjson_str_chunk |
struct | yyjson_str_pool |
struct | yyjson_val_chunk |
struct | yyjson_val_pool |
struct | yyjson_mut_doc |
Macros | |
#define | YYJSON_MSC_VER 0 |
#define | YYJSON_GCC_VER 0 |
#define | YYJSON_IS_REAL_GCC 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_feature(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_HAS_CONSTANT_P 0 |
#define | yyjson_deprecated(msg) |
#define | yyjson_api |
#define | yyjson_api_inline static yyjson_inline |
#define | __bool_true_false_are_defined 1 |
#define | YYJSON_U64_TO_F64_NO_IMPL 0 |
#define | YYJSON_VERSION_MAJOR 0 |
#define | YYJSON_VERSION_MINOR 10 |
#define | YYJSON_VERSION_PATCH 0 |
#define | YYJSON_VERSION_HEX 0x000A00 |
#define | YYJSON_VERSION_STRING "0.10.0" |
#define | YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */ |
#define | YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */ |
#define | YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */ |
#define | YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */ |
#define | YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */ |
#define | YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */ |
#define | YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */ |
#define | YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */ |
#define | YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */ |
#define | YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */ |
#define | YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */ |
#define | YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */ |
#define | YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */ |
#define | YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */ |
#define | YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */ |
#define | YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ |
#define | YYJSON_TYPE_BIT ((uint8_t)3) |
#define | YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */ |
#define | YYJSON_SUBTYPE_BIT ((uint8_t)2) |
#define | YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */ |
#define | YYJSON_RESERVED_BIT ((uint8_t)3) |
#define | YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */ |
#define | YYJSON_TAG_BIT ((uint8_t)8) |
#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 |
typedef uint32_t | yyjson_ptr_code |
typedef uint32_t | yyjson_patch_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). |
struct yyjson_arr_iter |
A JSON array iterator.
Data Fields | ||
---|---|---|
yyjson_val * | cur |
next value |
size_t | idx |
next value's index |
size_t | max |
maximum index (arr.size) |
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 |
next key |
size_t | idx |
next key's index |
size_t | max |
maximum key index (obj.size) |
yyjson_val * | obj |
the object being iterated |
struct yyjson_mut_arr_iter |
A mutable JSON array iterator.
yyjson_mut_arr_iter_remove()
to remove current value.Data Fields | ||
---|---|---|
yyjson_mut_val * | arr |
the array being iterated |
yyjson_mut_val * | cur |
current value |
size_t | idx |
next value's index |
size_t | max |
maximum index (arr.size) |
yyjson_mut_val * | pre |
previous value |
struct yyjson_mut_obj_iter |
A mutable JSON object iterator.
yyjson_mut_obj_iter_remove()
to remove current value.If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:
yyjson_mut_obj_iter_get()
and yyjson_mut_obj_iter_getn()
Data Fields | ||
---|---|---|
yyjson_mut_val * | cur |
current key |
size_t | idx |
next key's index |
size_t | max |
maximum key index (obj.size) |
yyjson_mut_val * | obj |
the object being iterated |
yyjson_mut_val * | pre |
previous key |
struct yyjson_ptr_err |
Error information for JSON pointer.
Data Fields | ||
---|---|---|
yyjson_ptr_code | code |
Error code, see |
const char * | msg |
Error message, constant, no need to free (NULL if no error). |
size_t | pos |
Error byte position for input JSON pointer (0 if no error). |
struct yyjson_ptr_ctx |
A context for JSON pointer operation.
This struct stores the context of JSON Pointer operation result. The struct can be used with three helper functions: ctx_append()
, ctx_replace()
, and ctx_remove()
, which perform the corresponding operations on the container without re-parsing the JSON Pointer.
For example:
Data Fields | ||
---|---|---|
yyjson_mut_val * | ctn |
The container (parent) of the target value. It can be either an array or an object. If the target location has no value, but all its parent containers exist, and the target location can be used to insert a new value, then |
yyjson_mut_val * | old |
The removed value if the operation is |
yyjson_mut_val * | pre |
The previous sibling of the target value. It can be either a value in an array or a key in an object. As the container is a |
struct yyjson_patch_err |
Error information for JSON patch.
Data Fields | ||
---|---|---|
yyjson_patch_code | code |
Error code, see |
size_t | idx |
Index of the error operation (0 if no error). |
const char * | msg |
Error message, constant, no need to free (NULL if no error). |
yyjson_ptr_err | ptr |
JSON pointer error if |
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_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. sizeof(yyjson_val_chunk)
should not larger than sizeof(yyjson_mut_val)
.
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 |
#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_deprecated | ( | msg | ) |
deprecate warning
#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_CONSTANT_P 0 |
compile-time constant check for compiler
#define yyjson_has_feature | ( | x | ) | 0 |
compiler feature check (since clang 2.6, icc 17)
#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_IS_REAL_GCC 0 |
real gcc check
#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_RESERVED_BIT ((uint8_t)3) |
The number of reserved bits.
#define YYJSON_RESERVED_MASK ((uint8_t)0xE0) /* 111_____ */ |
The mask used to extract the reserved bits of a JSON value.
#define YYJSON_STDC_VER 0 |
C version (STDC)
#define YYJSON_SUBTYPE_BIT ((uint8_t)2) |
The number of bits used by the subtype.
#define YYJSON_SUBTYPE_FALSE ((uint8_t)(0 << 3)) /* ___00___ */ |
False subtype: false
literal.
#define YYJSON_SUBTYPE_MASK ((uint8_t)0x18) /* ___11___ */ |
The mask used to extract the subtype of a JSON value.
#define YYJSON_SUBTYPE_NOESC ((uint8_t)(1 << 3)) /* ___01___ */ |
String that do not need to be escaped for writing (internal use).
#define YYJSON_SUBTYPE_NONE ((uint8_t)(0 << 3)) /* ___00___ */ |
No subtype.
#define YYJSON_SUBTYPE_REAL ((uint8_t)(2 << 3)) /* ___10___ */ |
Real number subtype: double
.
#define YYJSON_SUBTYPE_SINT ((uint8_t)(1 << 3)) /* ___01___ */ |
Signed integer subtype: int64_t
.
#define YYJSON_SUBTYPE_TRUE ((uint8_t)(1 << 3)) /* ___01___ */ |
True subtype: true
literal.
#define YYJSON_SUBTYPE_UINT ((uint8_t)(0 << 3)) /* ___00___ */ |
Unsigned integer subtype: uint64_t
.
#define YYJSON_TAG_BIT ((uint8_t)8) |
The number of bits used by the tag.
#define YYJSON_TAG_MASK ((uint8_t)0xFF) /* 11111111 */ |
The mask used to extract the tag of a JSON value.
#define YYJSON_TYPE_ARR ((uint8_t)6) /* _____110 */ |
Array type, no subtype.
#define YYJSON_TYPE_BIT ((uint8_t)3) |
The number of bits used by the type.
#define YYJSON_TYPE_BOOL ((uint8_t)3) /* _____011 */ |
Boolean type, subtype: TRUE, FALSE.
#define YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ |
The mask used to extract the type of a JSON value.
#define YYJSON_TYPE_NONE ((uint8_t)0) /* _____000 */ |
No type, invalid.
#define YYJSON_TYPE_NULL ((uint8_t)2) /* _____010 */ |
Null type: null
literal, no subtype.
#define YYJSON_TYPE_NUM ((uint8_t)4) /* _____100 */ |
Number type, subtype: UINT, SINT, REAL.
#define YYJSON_TYPE_OBJ ((uint8_t)7) /* _____111 */ |
Object type, no subtype.
#define YYJSON_TYPE_RAW ((uint8_t)1) /* _____001 */ |
Raw string type, no subtype.
#define YYJSON_TYPE_STR ((uint8_t)5) /* _____101 */ |
String type, subtype: NONE, NOESC.
#define YYJSON_U64_TO_F64_NO_IMPL 0 |
char bit check Microsoft Visual C++ 6.0 doesn't support converting number from u64 to f64: error C2520: conversion from unsigned __int64 to double not implemented.
#define yyjson_unlikely | ( | expr | ) | (expr) |
unlikely for compiler
#define YYJSON_VERSION_HEX 0x000A00 |
The version of yyjson in hex: (major << 16) | (minor << 8) | (patch)
.
#define YYJSON_VERSION_MAJOR 0 |
The major version of yyjson.
#define YYJSON_VERSION_MINOR 10 |
The minor version of yyjson.
#define YYJSON_VERSION_PATCH 0 |
The patch version of yyjson.
#define YYJSON_VERSION_STRING "0.10.0" |
The version string of yyjson.
typedef uint32_t yyjson_patch_code |
Result code for JSON patch.
typedef uint32_t yyjson_ptr_code |
JSON Pointer error code.
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 a JSON value (2 bit).
typedef uint8_t yyjson_type |
Type of a 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 void yyjson_alc_dyn_free | ( | yyjson_alc * | alc | ) |
Free a dynamic allocator which is created by yyjson_alc_dyn_new()
.
alc | The dynamic allocator to be destroyed. |
yyjson_api yyjson_alc * yyjson_alc_dyn_new | ( | void | ) |
A dynamic allocator.
This allocator has a similar usage to the pool allocator above. However, when there is not enough memory, this allocator will dynamically request more memory using libc's malloc
function, and frees it all at once when it is destroyed.
yyjson_alc_dyn_free()
.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 be used to avoid malloc/realloc calls. The pre-allocated memory should be held by the caller. The maximum amount of memory required to read a JSON can be calculated using the yyjson_read_max_memory_usage()
function, but the amount of memory required to write a JSON cannot be directly calculated.
This is not a general-purpose allocator. It is designed to handle a single JSON data at a time. If it is used for overly complex memory tasks, such as parsing multiple JSON documents using the same allocator but releasing only a few of them, it may cause memory fragmentation, resulting in performance degradation and memory waste.
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 will be set to an empty allocator. |
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.
[1,{},3]
is flat, [1,[2],3]
is not flat. 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.
[1,{},3]
is flat, [1,[2],3]
is not flat. 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 yyjson_arr_iter yyjson_arr_iter_with | ( | yyjson_val * | arr | ) |
Create an iterator with an array , same as yyjson_arr_iter_init()
.
arr | The array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned. |
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_deprecated | ( | "renamed to unsafe_yyjson_mut_ptr_getx" | ) |
unsafe_yyjson_mut_ptr_getx
yyjson_deprecated | ( | "renamed to unsafe_yyjson_ptr_getn" | ) |
yyjson_mut_ptr_getn
yyjson_deprecated | ( | "renamed to yyjson_doc_ptr_get" | ) |
yyjson_doc_ptr_get
yyjson_deprecated | ( | "renamed to yyjson_doc_ptr_getn" | ) |
yyjson_doc_ptr_getn
yyjson_deprecated | ( | "renamed to yyjson_mut_doc_ptr_get" | ) |
yyjson_mut_doc_ptr_get
yyjson_deprecated | ( | "renamed to yyjson_mut_doc_ptr_getn" | ) |
yyjson_mut_doc_ptr_getn
yyjson_deprecated | ( | "renamed to yyjson_mut_ptr_get" | ) |
yyjson_mut_ptr_get
yyjson_deprecated | ( | "renamed to yyjson_mut_ptr_getn" | ) |
yyjson_mut_ptr_getn
yyjson_deprecated | ( | "renamed to yyjson_ptr_get" | ) |
yyjson_ptr_get
yyjson_deprecated | ( | "renamed to yyjson_ptr_getn" | ) |
yyjson_ptr_getn
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 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.
imut_doc
-> mut_doc
. yyjson_api_inline yyjson_val * yyjson_doc_ptr_get | ( | yyjson_doc * | doc, |
const char * | ptr | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_val * yyjson_doc_ptr_getn | ( | yyjson_doc * | doc, |
const char * | ptr, | ||
size_t | len | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_val * yyjson_doc_ptr_getx | ( | yyjson_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_err * | err | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
err | A pointer to store the error information, or NULL if not needed. |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. 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 double yyjson_get_num | ( | yyjson_val * | val | ) |
Returns the content and typecast to double
if the value is number. Returns 0.0 if val
is NULL or type is not number(uint/sint/real).
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 bool yyjson_locate_pos | ( | const char * | str, |
size_t | len, | ||
size_t | pos, | ||
size_t * | line, | ||
size_t * | col, | ||
size_t * | chr | ||
) |
Locate the line and column number for a byte position in a string. This can be used to get better description for error position.
str | The input string. |
len | The byte length of the input string. |
pos | The byte position within the input string. |
line | A pointer to receive the line number, starting from 1. |
col | A pointer to receive the column number, starting from 1. |
chr | A pointer to receive the character index, starting from 0. |
str
is NULL or pos
is out of bounds. 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 yyjson_mut_arr_iter yyjson_mut_arr_iter_with | ( | yyjson_mut_val * | arr | ) |
Create an iterator with an array , same as yyjson_mut_arr_iter_init()
.
arr | The array to be iterated over. If this parameter is NULL or not an array, an empty iterator will returned. |
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_mut_arr_with_strcpy()
instead.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_mut_arr_with_strncpy()
instead.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_root | ( | yyjson_mut_doc * | doc | ) |
Returns the root value of this JSON document. Returns NULL if doc
is NULL.
yyjson_api yyjson_doc * yyjson_mut_doc_imut_copy | ( | yyjson_mut_doc * | doc, |
const yyjson_alc * | alc | ||
) |
Copies and returns a new immutable document from input, returns NULL on error. This makes a deep-copy
on the mutable document. The returned document should be freed with yyjson_doc_free()
.
mut_doc
-> imut_doc
. 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.
mut_doc
-> mut_doc
. 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 bool yyjson_mut_doc_ptr_add | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
yyjson_mut_val * | new_val | ||
) |
Add (insert) value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
new_val | The value to be added. |
yyjson_api_inline bool yyjson_mut_doc_ptr_addn | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val | ||
) |
Add (insert) value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be added. |
yyjson_api_inline bool yyjson_mut_doc_ptr_addx | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
bool | create_parent, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Add (insert) value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be added. |
create_parent | Whether to create parent nodes if not exist. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_get | ( | yyjson_mut_doc * | doc, |
const char * | ptr | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_getn | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_getx | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Get value by a JSON Pointer.
doc | The JSON document to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
doc
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_remove | ( | yyjson_mut_doc * | doc, |
const char * | ptr | ||
) |
Remove value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_removen | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len | ||
) |
Remove value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_removex | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Remove value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_replace | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
yyjson_mut_val * | new_val | ||
) |
Replace value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
new_val | The new value to replace the old one. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_replacen | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val | ||
) |
Replace value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The new value to replace the old one. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_ptr_replacex | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Replace value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The new value to replace the old one. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline bool yyjson_mut_doc_ptr_set | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
yyjson_mut_val * | new_val | ||
) |
Set value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
new_val | The value to be set, pass NULL to remove. |
yyjson_api_inline bool yyjson_mut_doc_ptr_setn | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val | ||
) |
Set value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be set, pass NULL to remove. |
yyjson_api_inline bool yyjson_mut_doc_ptr_setx | ( | yyjson_mut_doc * | doc, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
bool | create_parent, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Set value by a JSON pointer.
doc | The target JSON document. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be set, pass NULL to remove. |
create_parent | Whether to create parent nodes if not exist. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
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 bool yyjson_mut_doc_set_str_pool_size | ( | yyjson_mut_doc * | doc, |
size_t | len | ||
) |
Set the string pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed.
If the caller knows the approximate bytes of strings that the document needs to store (e.g. copy string with yyjson_mut_strcpy
function), setting a larger size can avoid multiple memory allocations and improve performance.
doc | The mutable document. |
len | The desired string pool size in bytes (total string length). |
yyjson_api bool yyjson_mut_doc_set_val_pool_size | ( | yyjson_mut_doc * | doc, |
size_t | count | ||
) |
Set the value pool size for a mutable document. This function does not allocate memory immediately, but uses the size when the next memory allocation is needed.
If the caller knows the approximate number of values that the document needs to store (e.g. create new value with yyjson_mut_xxx
functions), setting a larger size can avoid multiple memory allocations and improve performance.
doc | The mutable document. |
count | The desired value pool size (number of yyjson_mut_val ). |
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 double yyjson_mut_get_num | ( | yyjson_mut_val * | val | ) |
Returns the content and typecast to double
if the value is number. Returns 0.0 if val
is NULL or type is not number(uint/sint/real).
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 yyjson_mut_val * yyjson_mut_obj_add_arr | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key | ||
) |
Creates and adds a new array to the target 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_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 yyjson_mut_val * yyjson_mut_obj_add_obj | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key | ||
) |
Creates and adds a new object to the target 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 current key-value pair in the iteration, returns the removed value. If iter
is NULL, this function will return NULL.
yyjson_api_inline yyjson_mut_obj_iter yyjson_mut_obj_iter_with | ( | yyjson_mut_val * | obj | ) |
Create an iterator with an object, same as yyjson_obj_iter_init()
.
obj | The object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned. |
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_rename_key | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
const char * | new_key | ||
) |
Replaces all matching keys with the new key. Returns true if at least one key was renamed. The key
and new_key
should be a null-terminated UTF-8 string. The new_key
is copied and held by doc.
new_key
already exists, it will cause duplicate keys. yyjson_api_inline bool yyjson_mut_obj_rename_keyn | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | obj, | ||
const char * | key, | ||
size_t | len, | ||
const char * | new_key, | ||
size_t | new_len | ||
) |
Replaces all matching keys with the new key. Returns true if at least one key was renamed. The key
and new_key
should be a UTF-8 string, null-terminator is not required. The new_key
is copied and held by doc.
new_key
already exists, it will cause duplicate keys. 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 yyjson_mut_val * yyjson_mut_patch | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | orig, | ||
yyjson_mut_val * | patch, | ||
yyjson_patch_err * | err | ||
) |
Creates and returns a patched JSON value (RFC 6902). The memory of the returned value is allocated by the doc
. The err
is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied.
yyjson_api_inline bool yyjson_mut_ptr_add | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc | ||
) |
Add (insert) value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
doc | Only used to create new values when needed. |
new_val | The value to be added. |
yyjson_api_inline bool yyjson_mut_ptr_addn | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc | ||
) |
Add (insert) value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
doc | Only used to create new values when needed. |
new_val | The value to be added. |
yyjson_api_inline bool yyjson_mut_ptr_addx | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc, | ||
bool | create_parent, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Add (insert) value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
doc | Only used to create new values when needed. |
new_val | The value to be added. |
create_parent | Whether to create parent nodes if not exist. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_get | ( | yyjson_mut_val * | val, |
const char * | ptr | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_getn | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_getx | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_remove | ( | yyjson_mut_val * | val, |
const char * | ptr | ||
) |
Remove value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_removen | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len | ||
) |
Remove value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_removex | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Remove value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_replace | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
yyjson_mut_val * | new_val | ||
) |
Replace value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
new_val | The new value to replace the old one. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_replacen | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val | ||
) |
Replace value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The new value to replace the old one. |
yyjson_api_inline yyjson_mut_val * yyjson_mut_ptr_replacex | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Replace value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The new value to replace the old one. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
yyjson_api_inline bool yyjson_mut_ptr_set | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc | ||
) |
Set value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
new_val | The value to be set, pass NULL to remove. |
doc | Only used to create new values when needed. |
yyjson_api_inline bool yyjson_mut_ptr_setn | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc | ||
) |
Set value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be set, pass NULL to remove. |
doc | Only used to create new values when needed. |
yyjson_api_inline bool yyjson_mut_ptr_setx | ( | yyjson_mut_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_mut_val * | new_val, | ||
yyjson_mut_doc * | doc, | ||
bool | create_parent, | ||
yyjson_ptr_ctx * | ctx, | ||
yyjson_ptr_err * | err | ||
) |
Set value by a JSON pointer.
val | The target JSON value. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
new_val | The value to be set, pass NULL to remove. |
doc | Only used to create new values when needed. |
create_parent | Whether to create parent nodes if not exist. |
ctx | A pointer to store the result context, or NULL if not needed. |
err | A pointer to store the error information, or NULL if not needed. |
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 const char * yyjson_mut_read_number | ( | const char * | dat, |
yyjson_mut_val * | val, | ||
yyjson_read_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_read_err * | err | ||
) |
Read a JSON number.
This function is thread-safe when data is not modified by other threads.
dat | The JSON data (UTF-8 without BOM), null-terminator is required. If this parameter is NULL, the function will fail and return NULL. |
val | The output value where result is stored. If this parameter is NULL, the function will fail and return NULL. The value will hold either UINT or SINT or REAL number; |
flg | The JSON read options. Multiple options can be combined with | operator. 0 means no options. Supports YYJSON_READ_NUMBER_AS_RAW and YYJSON_READ_ALLOW_INF_AND_NAN . |
alc | The memory allocator used for long number. It is only used when the built-in floating point reader is disabled. 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 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 bool yyjson_mut_set_arr | ( | yyjson_mut_val * | val | ) |
Set the value to array. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_bool | ( | yyjson_mut_val * | val, |
bool | num | ||
) |
Set the value to bool. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_int | ( | yyjson_mut_val * | val, |
int | num | ||
) |
Set the value to int. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_null | ( | yyjson_mut_val * | val | ) |
Set the value to null. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_obj | ( | yyjson_mut_val * | val | ) |
Set the value to array. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_raw | ( | yyjson_mut_val * | val, |
const char * | raw, | ||
size_t | len | ||
) |
Set the value to raw. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_real | ( | yyjson_mut_val * | val, |
double | num | ||
) |
Set the value to real. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_sint | ( | yyjson_mut_val * | val, |
int64_t | num | ||
) |
Set the value to sint. Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_str | ( | yyjson_mut_val * | val, |
const char * | str | ||
) |
Set the value to string (null-terminated). Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_strn | ( | yyjson_mut_val * | val, |
const char * | str, | ||
size_t | len | ||
) |
Set the value to string (with length). Returns false if input is NULL.
yyjson_api_inline bool yyjson_mut_set_uint | ( | yyjson_mut_val * | val, |
uint64_t | num | ||
) |
Set the value to uint. Returns false if input is NULL.
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_doc * yyjson_mut_val_imut_copy | ( | yyjson_mut_val * | val, |
const yyjson_alc * | alc | ||
) |
Copies and returns a new immutable document from input, returns NULL on error. This makes a deep-copy
on the mutable value. The returned document should be freed with yyjson_doc_free()
.
mut_val
-> imut_doc
. yyjson_api yyjson_mut_val * yyjson_mut_val_mut_copy | ( | yyjson_mut_doc * | doc, |
yyjson_mut_val * | val | ||
) |
Copies and returns 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.
mut_val
-> mut_val
. 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 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 (not including the null-terminator). 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 bool yyjson_mut_val_write_fp | ( | FILE * | fp, |
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.
fp | The file pointer. The data will be written to the current position of the file. If this path is NULL or invalid, the function will fail and return false. |
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 (not including the null-terminator). 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 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 (not including the null-terminator). 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 bool yyjson_mut_write_fp | ( | FILE * | fp, |
const yyjson_mut_doc * | doc, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a document to file pointer with options.
fp | The file pointer. The data will be written to the current position of the file. If this fp is NULL or invalid, the function will fail and return false. |
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 (not including the null-terminator). 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 yyjson_obj_iter yyjson_obj_iter_with | ( | yyjson_val * | obj | ) |
Create an iterator with an object, same as yyjson_obj_iter_init()
.
obj | The object to be iterated over. If this parameter is NULL or not an object, an empty iterator will returned. |
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 yyjson_mut_val * yyjson_patch | ( | yyjson_mut_doc * | doc, |
yyjson_val * | orig, | ||
yyjson_val * | patch, | ||
yyjson_patch_err * | err | ||
) |
Creates and returns a patched JSON value (RFC 6902). The memory of the returned value is allocated by the doc
. The err
is used to receive error information, pass NULL if not needed. Returns NULL if the patch could not be applied.
yyjson_api_inline bool yyjson_ptr_ctx_append | ( | yyjson_ptr_ctx * | ctx, |
yyjson_mut_val * | key, | ||
yyjson_mut_val * | val | ||
) |
Append value by JSON pointer context.
ctx | The context from the yyjson_mut_ptr_xxx() calls. |
key | New key if ctx->ctn is object, or NULL if ctx->ctn is array. |
val | New value to be added. |
yyjson_api_inline bool yyjson_ptr_ctx_remove | ( | yyjson_ptr_ctx * | ctx | ) |
Remove value by JSON pointer context.
ctx | The context from the yyjson_mut_ptr_xxx() calls. |
ctx->old
. yyjson_api_inline bool yyjson_ptr_ctx_replace | ( | yyjson_ptr_ctx * | ctx, |
yyjson_mut_val * | val | ||
) |
Replace value by JSON pointer context.
ctx | The context from the yyjson_mut_ptr_xxx() calls. |
val | New value to be replaced. |
ctx->old
. yyjson_api_inline yyjson_val * yyjson_ptr_get | ( | yyjson_val * | val, |
const char * | ptr | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8 with null-terminator). |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline bool yyjson_ptr_get_bool | ( | yyjson_val * | root, |
const char * | ptr, | ||
bool * | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is type bool. Returns true if value at ptr
exists and is the correct type, otherwise false.
yyjson_api_inline bool yyjson_ptr_get_num | ( | yyjson_val * | root, |
const char * | ptr, | ||
double * | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is type sint, uint or real. Returns true if value at ptr
exists and is the correct type, otherwise false.
yyjson_api_inline bool yyjson_ptr_get_real | ( | yyjson_val * | root, |
const char * | ptr, | ||
double * | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is type real. Returns true if value at ptr
exists and is the correct type, otherwise false.
yyjson_api_inline bool yyjson_ptr_get_sint | ( | yyjson_val * | root, |
const char * | ptr, | ||
int64_t * | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is an integer that fits in int64_t
. Returns true if successful, otherwise false.
yyjson_api_inline bool yyjson_ptr_get_str | ( | yyjson_val * | root, |
const char * | ptr, | ||
const char ** | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is type string. Returns true if value at ptr
exists and is the correct type, otherwise false.
yyjson_api_inline bool yyjson_ptr_get_uint | ( | yyjson_val * | root, |
const char * | ptr, | ||
uint64_t * | value | ||
) |
Set provided value
if the JSON Pointer (RFC 6901) exists and is an integer that fits in uint64_t
. Returns true if successful, otherwise false.
yyjson_api_inline yyjson_val * yyjson_ptr_getn | ( | yyjson_val * | val, |
const char * | ptr, | ||
size_t | len | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. yyjson_api_inline yyjson_val * yyjson_ptr_getx | ( | yyjson_val * | val, |
const char * | ptr, | ||
size_t | len, | ||
yyjson_ptr_err * | err | ||
) |
Get value by a JSON Pointer.
val | The JSON value to be queried. |
ptr | The JSON pointer string (UTF-8, null-terminator is not required). |
len | The length of ptr in bytes. |
err | A pointer to store the error information, or NULL if not needed. |
val
or ptr
is NULL, or the JSON pointer cannot be resolved. 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_doc_free()
. 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_doc_free()
.yyjson_api yyjson_doc * yyjson_read_fp | ( | FILE * | fp, |
yyjson_read_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_read_err * | err | ||
) |
Read JSON from a file pointer.
fp | The file pointer. The data will be read from the current position of the FILE to the end. If this fp 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_doc_free()
.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 const char * yyjson_read_number | ( | const char * | dat, |
yyjson_val * | val, | ||
yyjson_read_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_read_err * | err | ||
) |
Read a JSON number.
This function is thread-safe when data is not modified by other threads.
dat | The JSON data (UTF-8 without BOM), null-terminator is required. If this parameter is NULL, the function will fail and return NULL. |
val | The output value where result is stored. If this parameter is NULL, the function will fail and return NULL. The value will hold either UINT or SINT or REAL number; |
flg | The JSON read options. Multiple options can be combined with | operator. 0 means no options. Supports YYJSON_READ_NUMBER_AS_RAW and YYJSON_READ_ALLOW_INF_AND_NAN . |
alc | The memory allocator used for long number. It is only used when the built-in floating point reader is disabled. 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_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_doc_free()
. yyjson_api_inline bool yyjson_set_bool | ( | yyjson_val * | val, |
bool | num | ||
) |
Set the value to bool. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_int | ( | yyjson_val * | val, |
int | num | ||
) |
Set the value to int. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_null | ( | yyjson_val * | val | ) |
Set the value to null. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_raw | ( | yyjson_val * | val, |
const char * | raw, | ||
size_t | len | ||
) |
Set the value to raw. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_real | ( | yyjson_val * | val, |
double | num | ||
) |
Set the value to real. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_sint | ( | yyjson_val * | val, |
int64_t | num | ||
) |
Set the value to sint. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_str | ( | yyjson_val * | val, |
const char * | str | ||
) |
Set the value to string (null-terminated). Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_strn | ( | yyjson_val * | val, |
const char * | str, | ||
size_t | len | ||
) |
Set the value to string (with length). Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. yyjson_api_inline bool yyjson_set_uint | ( | yyjson_val * | val, |
uint64_t | num | ||
) |
Set the value to uint. Returns false if input is NULL or val
is object or array.
immutable
value, use with caution. 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.
imut_val
-> mut_val
. 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 (not including the null-terminator). 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 bool yyjson_val_write_fp | ( | FILE * | fp, |
const yyjson_val * | val, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a value to file pointer with options.
fp | The file pointer. The data will be written to the current position of the file. If this path is NULL or invalid, the function will fail and return false. |
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 (not including the null-terminator). 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 (not including the null-terminator). 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 bool yyjson_write_fp | ( | FILE * | fp, |
const yyjson_doc * | doc, | ||
yyjson_write_flag | flg, | ||
const yyjson_alc * | alc, | ||
yyjson_write_err * | err | ||
) |
Write a document to file pointer with options.
fp | The file pointer. The data will be written to the current position of the file. If this fp is NULL or invalid, the function will fail and return false. |
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 (not including the null-terminator). 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 |
JSON patch operation test
not equal.
|
static |
JSON patch operation member is invalid.
|
static |
JSON patch operation is not object type.
|
static |
Invalid parameter, such as NULL input or non-array patch.
|
static |
Memory allocation failure occurs.
|
static |
JSON patch operation is missing a required key.
|
static |
JSON patch operation failed on JSON pointer.
|
static |
Success, no error.
|
static |
The memory allocation failed and a new value could not be created.
|
static |
No JSON pointer error.
|
static |
Document's root is NULL, but it is required for the function call.
|
static |
Invalid input parameter, such as NULL input.
|
static |
JSON pointer resolve failed, such as index out of range, key not found.
|
static |
Cannot set root as the target is not a document.
|
static |
JSON pointer syntax error, such as invalid escape, token no prefix.
|
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 |
Read big numbers as raw strings. These big numbers include integers that cannot be represented by int64_t
and uint64_t
, and floating-point numbers that cannot be represented by finite double
. The flag will be overridden by YYJSON_READ_NUMBER_AS_RAW
flag.
|
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 input string or 0 input length.
|
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 [abc]
.
|
static |
Unexpected content after document, such as [123]abc
.
|
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
, input length should be 5.
|
static |
Default option (RFC 8259 compliant):
|
static |
Read all numbers as raw strings (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 |
Adds a newline character \n
at the end of the JSON. This can be helpful for text editors or NDJSON.
|
static |
Default option:
|
static |
Write JSON pretty with 4 space indent.
|
static |
Write JSON pretty with 2 space indent. This flag will override YYJSON_WRITE_PRETTY
flag.
|
static |
Success, no error.