yyjson 0.5.0
A high performance C JSON library.
yyjson.h File Reference
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
#include <string.h>
#include <float.h>

Data Structures

struct  yyjson_alc
 
struct  yyjson_read_err
 
struct  yyjson_write_err
 
union  yyjson_val_uni
 
struct  yyjson_val
 
struct  yyjson_doc
 
struct  yyjson_arr_iter
 
struct  yyjson_obj_iter
 
struct  yyjson_mut_val
 
struct  yyjson_str_chunk
 
struct  yyjson_str_pool
 
struct  yyjson_val_chunk
 
struct  yyjson_val_pool
 
struct  yyjson_mut_doc
 
struct  yyjson_mut_arr_iter
 
struct  yyjson_mut_obj_iter
 

Macros

#define YYJSON_MSC_VER   0
 
#define YYJSON_GCC_VER   0
 
#define YYJSON_STDC_VER   0
 
#define YYJSON_CPP_VER   0
 
#define yyjson_has_builtin(x)   0
 
#define yyjson_has_attribute(x)   0
 
#define yyjson_has_include(x)   0
 
#define yyjson_inline
 
#define yyjson_noinline
 
#define yyjson_align(x)
 
#define yyjson_likely(expr)   (expr)
 
#define yyjson_unlikely(expr)   (expr)
 
#define yyjson_api
 
#define yyjson_api_inline   static yyjson_inline
 
#define __bool_true_false_are_defined   1
 
#define YYJSON_VERSION_MAJOR   0
 
#define YYJSON_VERSION_MINOR   5
 
#define YYJSON_VERSION_PATCH   0
 
#define YYJSON_VERSION_HEX   0x000500
 
#define YYJSON_VERSION_STRING   "0.5.0"
 
#define YYJSON_TYPE_MASK   ((uint8_t)0x07) /* _____111 */
 
#define YYJSON_PADDING_SIZE   4
 
#define yyjson_arr_foreach(arr, idx, max, val)
 
#define yyjson_obj_foreach(obj, idx, max, key, val)
 
#define yyjson_mut_arr_foreach(arr, idx, max, val)
 
#define yyjson_mut_obj_foreach(obj, idx, max, key, val)
 

Typedefs

typedef uint8_t yyjson_type
 
typedef uint8_t yyjson_subtype
 
typedef uint32_t yyjson_read_flag
 
typedef uint32_t yyjson_read_code
 
typedef uint32_t yyjson_write_flag
 
typedef uint32_t yyjson_write_code
 

Functions

yyjson_api uint32_t yyjson_version (void)
 
yyjson_api bool yyjson_alc_pool_init (yyjson_alc *alc, void *buf, size_t size)
 
yyjson_api yyjson_docyyjson_read_opts (char *dat, size_t len, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err)
 
yyjson_api yyjson_docyyjson_read_file (const char *path, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err)
 
yyjson_api_inline yyjson_docyyjson_read (const char *dat, size_t len, yyjson_read_flag flg)
 
yyjson_api_inline size_t yyjson_read_max_memory_usage (size_t len, yyjson_read_flag flg)
 
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)
 
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)
 
yyjson_api_inline char * yyjson_write (const yyjson_doc *doc, yyjson_write_flag flg, size_t *len)
 
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)
 
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)
 
yyjson_api_inline char * yyjson_mut_write (const yyjson_mut_doc *doc, yyjson_write_flag flg, size_t *len)
 
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)
 
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)
 
yyjson_api_inline char * yyjson_val_write (const yyjson_val *val, yyjson_write_flag flg, size_t *len)
 
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)
 
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)
 
yyjson_api_inline char * yyjson_mut_val_write (const yyjson_mut_val *val, yyjson_write_flag flg, size_t *len)
 
yyjson_api_inline yyjson_valyyjson_doc_get_root (yyjson_doc *doc)
 
yyjson_api_inline size_t yyjson_doc_get_read_size (yyjson_doc *doc)
 
yyjson_api_inline size_t yyjson_doc_get_val_count (yyjson_doc *doc)
 
yyjson_api_inline void yyjson_doc_free (yyjson_doc *doc)
 
yyjson_api_inline bool yyjson_is_raw (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_null (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_true (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_false (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_bool (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_uint (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_sint (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_int (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_real (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_num (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_str (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_arr (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_obj (yyjson_val *val)
 
yyjson_api_inline bool yyjson_is_ctn (yyjson_val *val)
 
yyjson_api_inline yyjson_type yyjson_get_type (yyjson_val *val)
 
yyjson_api_inline yyjson_subtype yyjson_get_subtype (yyjson_val *val)
 
yyjson_api_inline uint8_t yyjson_get_tag (yyjson_val *val)
 
yyjson_api_inline const char * yyjson_get_type_desc (yyjson_val *val)
 
yyjson_api_inline const char * yyjson_get_raw (yyjson_val *val)
 
yyjson_api_inline bool yyjson_get_bool (yyjson_val *val)
 
yyjson_api_inline uint64_t yyjson_get_uint (yyjson_val *val)
 
yyjson_api_inline int64_t yyjson_get_sint (yyjson_val *val)
 
yyjson_api_inline int yyjson_get_int (yyjson_val *val)
 
yyjson_api_inline double yyjson_get_real (yyjson_val *val)
 
yyjson_api_inline const char * yyjson_get_str (yyjson_val *val)
 
yyjson_api_inline size_t yyjson_get_len (yyjson_val *val)
 
yyjson_api_inline bool yyjson_equals_str (yyjson_val *val, const char *str)
 
yyjson_api_inline bool yyjson_equals_strn (yyjson_val *val, const char *str, size_t len)
 
yyjson_api_inline bool yyjson_equals (yyjson_val *lhs, yyjson_val *rhs)
 
yyjson_api_inline size_t yyjson_arr_size (yyjson_val *arr)
 
yyjson_api_inline yyjson_valyyjson_arr_get (yyjson_val *arr, size_t idx)
 
yyjson_api_inline yyjson_valyyjson_arr_get_first (yyjson_val *arr)
 
yyjson_api_inline yyjson_valyyjson_arr_get_last (yyjson_val *arr)
 
yyjson_api_inline bool yyjson_arr_iter_init (yyjson_val *arr, yyjson_arr_iter *iter)
 
yyjson_api_inline bool yyjson_arr_iter_has_next (yyjson_arr_iter *iter)
 
yyjson_api_inline yyjson_valyyjson_arr_iter_next (yyjson_arr_iter *iter)
 
yyjson_api_inline size_t yyjson_obj_size (yyjson_val *obj)
 
yyjson_api_inline yyjson_valyyjson_obj_get (yyjson_val *obj, const char *key)
 
yyjson_api_inline yyjson_valyyjson_obj_getn (yyjson_val *obj, const char *key, size_t key_len)
 
yyjson_api_inline bool yyjson_obj_iter_init (yyjson_val *obj, yyjson_obj_iter *iter)
 
yyjson_api_inline bool yyjson_obj_iter_has_next (yyjson_obj_iter *iter)
 
yyjson_api_inline yyjson_valyyjson_obj_iter_next (yyjson_obj_iter *iter)
 
yyjson_api_inline yyjson_valyyjson_obj_iter_get_val (yyjson_val *key)
 
yyjson_api_inline yyjson_valyyjson_obj_iter_get (yyjson_obj_iter *iter, const char *key)
 
yyjson_api_inline yyjson_valyyjson_obj_iter_getn (yyjson_obj_iter *iter, const char *key, size_t key_len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_doc_get_root (yyjson_mut_doc *doc)
 
yyjson_api_inline void yyjson_mut_doc_set_root (yyjson_mut_doc *doc, yyjson_mut_val *root)
 
yyjson_api void yyjson_mut_doc_free (yyjson_mut_doc *doc)
 
yyjson_api yyjson_mut_docyyjson_mut_doc_new (const yyjson_alc *alc)
 
yyjson_api yyjson_mut_docyyjson_doc_mut_copy (yyjson_doc *doc, const yyjson_alc *alc)
 
yyjson_api yyjson_mut_docyyjson_mut_doc_mut_copy (yyjson_mut_doc *doc, const yyjson_alc *alc)
 
yyjson_api yyjson_mut_valyyjson_val_mut_copy (yyjson_mut_doc *doc, yyjson_val *val)
 
yyjson_api yyjson_mut_valyyjson_mut_val_mut_copy (yyjson_mut_doc *doc, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_raw (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_null (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_true (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_false (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_bool (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_uint (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_sint (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_int (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_real (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_num (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_str (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_arr (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_obj (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_is_ctn (yyjson_mut_val *val)
 
yyjson_api_inline yyjson_type yyjson_mut_get_type (yyjson_mut_val *val)
 
yyjson_api_inline yyjson_subtype yyjson_mut_get_subtype (yyjson_mut_val *val)
 
yyjson_api_inline uint8_t yyjson_mut_get_tag (yyjson_mut_val *val)
 
yyjson_api_inline const char * yyjson_mut_get_type_desc (yyjson_mut_val *val)
 
yyjson_api_inline const char * yyjson_mut_get_raw (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_get_bool (yyjson_mut_val *val)
 
yyjson_api_inline uint64_t yyjson_mut_get_uint (yyjson_mut_val *val)
 
yyjson_api_inline int64_t yyjson_mut_get_sint (yyjson_mut_val *val)
 
yyjson_api_inline int yyjson_mut_get_int (yyjson_mut_val *val)
 
yyjson_api_inline double yyjson_mut_get_real (yyjson_mut_val *val)
 
yyjson_api_inline const char * yyjson_mut_get_str (yyjson_mut_val *val)
 
yyjson_api_inline size_t yyjson_mut_get_len (yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_equals_str (yyjson_mut_val *val, const char *str)
 
yyjson_api_inline bool yyjson_mut_equals_strn (yyjson_mut_val *val, const char *str, size_t len)
 
yyjson_api_inline bool yyjson_mut_equals (yyjson_mut_val *lhs, yyjson_mut_val *rhs)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_raw (yyjson_mut_doc *doc, const char *str)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_rawn (yyjson_mut_doc *doc, const char *str, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_rawcpy (yyjson_mut_doc *doc, const char *str)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_rawncpy (yyjson_mut_doc *doc, const char *str, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_null (yyjson_mut_doc *doc)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_true (yyjson_mut_doc *doc)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_false (yyjson_mut_doc *doc)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_bool (yyjson_mut_doc *doc, bool val)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_uint (yyjson_mut_doc *doc, uint64_t num)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_sint (yyjson_mut_doc *doc, int64_t num)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_int (yyjson_mut_doc *doc, int64_t num)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_real (yyjson_mut_doc *doc, double num)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_str (yyjson_mut_doc *doc, const char *str)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_strn (yyjson_mut_doc *doc, const char *str, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_strcpy (yyjson_mut_doc *doc, const char *str)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_strncpy (yyjson_mut_doc *doc, const char *str, size_t len)
 
yyjson_api_inline size_t yyjson_mut_arr_size (yyjson_mut_val *arr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_get (yyjson_mut_val *arr, size_t idx)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_get_first (yyjson_mut_val *arr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_get_last (yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_iter_init (yyjson_mut_val *arr, yyjson_mut_arr_iter *iter)
 
yyjson_api_inline bool yyjson_mut_arr_iter_has_next (yyjson_mut_arr_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_iter_next (yyjson_mut_arr_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_iter_remove (yyjson_mut_arr_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr (yyjson_mut_doc *doc)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_bool (yyjson_mut_doc *doc, const bool *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_sint (yyjson_mut_doc *doc, const int64_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_uint (yyjson_mut_doc *doc, const uint64_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_real (yyjson_mut_doc *doc, const double *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_sint8 (yyjson_mut_doc *doc, const int8_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_sint16 (yyjson_mut_doc *doc, const int16_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_sint32 (yyjson_mut_doc *doc, const int32_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_sint64 (yyjson_mut_doc *doc, const int64_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_uint8 (yyjson_mut_doc *doc, const uint8_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_uint16 (yyjson_mut_doc *doc, const uint16_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_uint32 (yyjson_mut_doc *doc, const uint32_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_uint64 (yyjson_mut_doc *doc, const uint64_t *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_float (yyjson_mut_doc *doc, const float *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_double (yyjson_mut_doc *doc, const double *vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_str (yyjson_mut_doc *doc, const char **vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_strn (yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_strcpy (yyjson_mut_doc *doc, const char **vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_with_strncpy (yyjson_mut_doc *doc, const char **vals, const size_t *lens, size_t count)
 
yyjson_api_inline bool yyjson_mut_arr_insert (yyjson_mut_val *arr, yyjson_mut_val *val, size_t idx)
 
yyjson_api_inline bool yyjson_mut_arr_append (yyjson_mut_val *arr, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_arr_prepend (yyjson_mut_val *arr, yyjson_mut_val *val)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_replace (yyjson_mut_val *arr, size_t idx, yyjson_mut_val *val)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_remove (yyjson_mut_val *arr, size_t idx)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_remove_first (yyjson_mut_val *arr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_remove_last (yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_remove_range (yyjson_mut_val *arr, size_t idx, size_t len)
 
yyjson_api_inline bool yyjson_mut_arr_clear (yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_rotate (yyjson_mut_val *arr, size_t idx)
 
yyjson_api_inline bool yyjson_mut_arr_add_val (yyjson_mut_val *arr, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_arr_add_null (yyjson_mut_doc *doc, yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_add_true (yyjson_mut_doc *doc, yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_add_false (yyjson_mut_doc *doc, yyjson_mut_val *arr)
 
yyjson_api_inline bool yyjson_mut_arr_add_bool (yyjson_mut_doc *doc, yyjson_mut_val *arr, bool val)
 
yyjson_api_inline bool yyjson_mut_arr_add_uint (yyjson_mut_doc *doc, yyjson_mut_val *arr, uint64_t num)
 
yyjson_api_inline bool yyjson_mut_arr_add_sint (yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num)
 
yyjson_api_inline bool yyjson_mut_arr_add_int (yyjson_mut_doc *doc, yyjson_mut_val *arr, int64_t num)
 
yyjson_api_inline bool yyjson_mut_arr_add_real (yyjson_mut_doc *doc, yyjson_mut_val *arr, double num)
 
yyjson_api_inline bool yyjson_mut_arr_add_str (yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str)
 
yyjson_api_inline bool yyjson_mut_arr_add_strn (yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len)
 
yyjson_api_inline bool yyjson_mut_arr_add_strcpy (yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str)
 
yyjson_api_inline bool yyjson_mut_arr_add_strncpy (yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_add_arr (yyjson_mut_doc *doc, yyjson_mut_val *arr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_arr_add_obj (yyjson_mut_doc *doc, yyjson_mut_val *arr)
 
yyjson_api_inline size_t yyjson_mut_obj_size (yyjson_mut_val *obj)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_get (yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_getn (yyjson_mut_val *obj, const char *key, size_t key_len)
 
yyjson_api_inline bool yyjson_mut_obj_iter_init (yyjson_mut_val *obj, yyjson_mut_obj_iter *iter)
 
yyjson_api_inline bool yyjson_mut_obj_iter_has_next (yyjson_mut_obj_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_iter_next (yyjson_mut_obj_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_iter_get_val (yyjson_mut_val *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_iter_remove (yyjson_mut_obj_iter *iter)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_iter_get (yyjson_mut_obj_iter *iter, const char *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_iter_getn (yyjson_mut_obj_iter *iter, const char *key, size_t key_len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj (yyjson_mut_doc *doc)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_with_str (yyjson_mut_doc *doc, const char **keys, const char **vals, size_t count)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_with_kv (yyjson_mut_doc *doc, const char **kv_pairs, size_t pair_count)
 
yyjson_api_inline bool yyjson_mut_obj_add (yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_obj_put (yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_obj_insert (yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val, size_t idx)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_remove (yyjson_mut_val *obj, yyjson_mut_val *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_remove_key (yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_remove_keyn (yyjson_mut_val *obj, const char *key, size_t key_len)
 
yyjson_api_inline bool yyjson_mut_obj_clear (yyjson_mut_val *obj)
 
yyjson_api_inline bool yyjson_mut_obj_replace (yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val)
 
yyjson_api_inline bool yyjson_mut_obj_rotate (yyjson_mut_val *obj, size_t idx)
 
yyjson_api_inline bool yyjson_mut_obj_add_null (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline bool yyjson_mut_obj_add_true (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline bool yyjson_mut_obj_add_false (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline bool yyjson_mut_obj_add_bool (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, bool val)
 
yyjson_api_inline bool yyjson_mut_obj_add_uint (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, uint64_t val)
 
yyjson_api_inline bool yyjson_mut_obj_add_sint (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, int64_t val)
 
yyjson_api_inline bool yyjson_mut_obj_add_int (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, int64_t val)
 
yyjson_api_inline bool yyjson_mut_obj_add_real (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, double val)
 
yyjson_api_inline bool yyjson_mut_obj_add_str (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val)
 
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)
 
yyjson_api_inline bool yyjson_mut_obj_add_strcpy (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val)
 
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)
 
yyjson_api_inline bool yyjson_mut_obj_add_val (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, yyjson_mut_val *val)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_remove_str (yyjson_mut_val *obj, const char *key)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_obj_remove_strn (yyjson_mut_val *obj, const char *key, size_t len)
 
yyjson_api_inline yyjson_valyyjson_get_pointer (yyjson_val *val, const char *ptr)
 
yyjson_api_inline yyjson_valyyjson_get_pointern (yyjson_val *val, const char *ptr, size_t len)
 
yyjson_api_inline yyjson_valyyjson_doc_get_pointer (yyjson_doc *doc, const char *ptr)
 
yyjson_api_inline yyjson_valyyjson_doc_get_pointern (yyjson_doc *doc, const char *ptr, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_get_pointer (yyjson_mut_val *val, const char *ptr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_get_pointern (yyjson_mut_val *val, const char *ptr, size_t len)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_doc_get_pointer (yyjson_mut_doc *doc, const char *ptr)
 
yyjson_api_inline yyjson_mut_valyyjson_mut_doc_get_pointern (yyjson_mut_doc *doc, const char *ptr, size_t len)
 
yyjson_api yyjson_mut_valyyjson_merge_patch (yyjson_mut_doc *doc, yyjson_val *orig, yyjson_val *patch)
 
yyjson_api yyjson_mut_valyyjson_mut_merge_patch (yyjson_mut_doc *doc, yyjson_mut_val *orig, yyjson_mut_val *patch)
 

Variables

static const yyjson_read_flag YYJSON_READ_NOFLAG = 0 << 0
 
static const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0
 
static const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1
 
static const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2
 
static const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3
 
static const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4
 
static const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5
 
static const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6
 
static const yyjson_read_code YYJSON_READ_SUCCESS = 0
 
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1
 
static const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2
 
static const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3
 
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4
 
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5
 
static const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6
 
static const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7
 
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8
 
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9
 
static const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10
 
static const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11
 
static const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12
 
static const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13
 
static const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0 << 0
 
static const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0
 
static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1
 
static const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2
 
static const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3
 
static const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4
 
static const yyjson_read_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5
 
static const yyjson_write_code YYJSON_WRITE_SUCCESS = 0
 
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1
 
static const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2
 
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3
 
static const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4
 
static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5
 
static const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6
 
static const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7
 

Data Structure Documentation

◆ yyjson_read_err

struct yyjson_read_err

Error information for JSON reader.

Data Fields
yyjson_read_code code

Error code, see yyjson_read_code for all possible values.

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

◆ yyjson_write_err

struct yyjson_write_err

Error information for JSON writer.

Data Fields
yyjson_write_code code

Error code, see yyjson_write_code for all possible values.

const char * msg

Error message, constant, no need to free (NULL if success).

◆ yyjson_val_uni

union yyjson_val_uni

Payload of a JSON value (8 bytes).

◆ yyjson_val

struct yyjson_val

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

◆ yyjson_doc

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

◆ yyjson_arr_iter

struct yyjson_arr_iter

A JSON array iterator.

Example
while ((val = yyjson_arr_iter_next(&iter))) {
your_func(val);
}
yyjson_api_inline bool yyjson_arr_iter_init(yyjson_val *arr, yyjson_arr_iter *iter)
Definition: yyjson.h:3676
yyjson_api_inline yyjson_val * yyjson_arr_iter_next(yyjson_arr_iter *iter)
Definition: yyjson.h:3692
Definition: yyjson.h:3670
Definition: yyjson.h:3266
Data Fields
yyjson_val * cur

current value

size_t idx

current index, from 0

size_t max

maximum index, idx < max

◆ yyjson_obj_iter

struct yyjson_obj_iter

A JSON object iterator.

Example
yyjson_val *key, *val;
while ((key = yyjson_obj_iter_next(&iter))) {
your_func(key, val);
}
yyjson_api_inline bool yyjson_obj_iter_init(yyjson_val *obj, yyjson_obj_iter *iter)
Definition: yyjson.h:3749
yyjson_api_inline yyjson_val * yyjson_obj_iter_get_val(yyjson_val *key)
Definition: yyjson.h:3776
yyjson_api_inline yyjson_val * yyjson_obj_iter_next(yyjson_obj_iter *iter)
Definition: yyjson.h:3766
yyjson_val * obj
Definition: yyjson.h:3746
Definition: yyjson.h:3742

If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:

// {"k1":1, "k2": 3, "k3": 3}
yyjson_val *key, *val;
yyjson_val *v1 = yyjson_obj_iter_get(&iter, "k1");
yyjson_val *v3 = yyjson_obj_iter_get(&iter, "k3");
yyjson_api_inline yyjson_val * yyjson_obj_iter_get(yyjson_obj_iter *iter, const char *key)
Definition: yyjson.h:3780
See also
yyjson_obj_iter_get() and yyjson_obj_iter_getn()
Data Fields
yyjson_val * cur

current key

size_t idx

current key index, from 0

size_t max

maximum key index, idx < max

yyjson_val * obj

the object being iterated

◆ yyjson_mut_val

struct yyjson_mut_val

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.

◆ yyjson_str_chunk

struct yyjson_str_chunk

◆ yyjson_str_pool

struct yyjson_str_pool

◆ yyjson_val_chunk

struct yyjson_val_chunk

◆ yyjson_val_pool

struct yyjson_val_pool

◆ yyjson_mut_doc

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

◆ yyjson_mut_arr_iter

struct yyjson_mut_arr_iter

A mutable JSON array iterator.

Warning
You should not modify the array while iterating over it, but you can use yyjson_mut_arr_iter_remove() to remove current value.
Example
while ((val = yyjson_mut_arr_iter_next(&iter))) {
your_func(val);
if (your_val_is_unused(val)) {
}
}
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_iter_remove(yyjson_mut_arr_iter *iter)
Definition: yyjson.h:4316
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_iter_next(yyjson_mut_arr_iter *iter)
Definition: yyjson.h:4304
yyjson_mut_val * arr
Definition: yyjson.h:4283
yyjson_api_inline bool yyjson_mut_arr_iter_init(yyjson_mut_val *arr, yyjson_mut_arr_iter *iter)
Definition: yyjson.h:4286
Definition: yyjson.h:4278
Definition: yyjson.h:3826
Data Fields
yyjson_mut_val * arr

the array being iterated

yyjson_mut_val * cur

current value

size_t idx

current index, from 0

size_t max

maximum index, idx < max

yyjson_mut_val * pre

previous value

◆ yyjson_mut_obj_iter

struct yyjson_mut_obj_iter

A mutable JSON object iterator.

Warning
You should not modify the object while iterating over it, but you can use yyjson_mut_obj_iter_remove() to remove current value.
Example
yyjson_mut_val *key, *val;
while ((key = yyjson_mut_obj_iter_next(&iter))) {
your_func(key, val);
if (your_val_is_unused(key, val)) {
}
}
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_next(yyjson_mut_obj_iter *iter)
Definition: yyjson.h:4944
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_remove(yyjson_mut_obj_iter *iter)
Definition: yyjson.h:4961
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_get_val(yyjson_mut_val *key)
Definition: yyjson.h:4956
yyjson_mut_val * obj
Definition: yyjson.h:4923
yyjson_api_inline bool yyjson_mut_obj_iter_init(yyjson_mut_val *obj, yyjson_mut_obj_iter *iter)
Definition: yyjson.h:4926
Definition: yyjson.h:4918

If the ordering of the keys is known at compile-time, you can use this method to speed up value lookups:

// {"k1":1, "k2": 3, "k3": 3}
yyjson_mut_val *key, *val;
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_get(yyjson_mut_obj_iter *iter, const char *key)
Definition: yyjson.h:4978
See also
yyjson_mut_obj_iter_get() and yyjson_mut_obj_iter_getn()
Data Fields
yyjson_mut_val * cur

current key

size_t idx

current key index, from 0

size_t max

maximum key index, idx < max

yyjson_mut_val * obj

the object being iterated

yyjson_mut_val * pre

previous key

Macro Definition Documentation

◆ __bool_true_false_are_defined

#define __bool_true_false_are_defined   1

stdint (C89 compatible) stdbool (C89 compatible)

◆ yyjson_align

#define yyjson_align (   x)

align for compiler

◆ yyjson_api

#define yyjson_api

function export

◆ yyjson_api_inline

#define yyjson_api_inline   static yyjson_inline

inline function export

◆ yyjson_arr_foreach

#define yyjson_arr_foreach (   arr,
  idx,
  max,
  val 
)
Value:
for ((idx) = 0, \
(max) = yyjson_arr_size(arr), \
(val) = yyjson_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = unsafe_yyjson_get_next(val))
yyjson_api_inline size_t yyjson_arr_size(yyjson_val *arr)
Definition: yyjson.h:3620
yyjson_api_inline yyjson_val * yyjson_arr_get_first(yyjson_val *arr)
Definition: yyjson.h:3639

Macro for iterating over an array. It works like iterator, but with a more intuitive API.

Example
size_t idx, max;
yyjson_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
#define yyjson_arr_foreach(arr, idx, max, val)
Definition: yyjson.h:1440

◆ YYJSON_CPP_VER

#define YYJSON_CPP_VER   0

C++ version

◆ YYJSON_GCC_VER

#define YYJSON_GCC_VER   0

compiler version (GCC)

◆ yyjson_has_attribute

#define yyjson_has_attribute (   x)    0

compiler attribute check (since gcc 5.0, clang 2.9, icc 17)

◆ yyjson_has_builtin

#define yyjson_has_builtin (   x)    0

compiler builtin check (since gcc 10.0, clang 2.6, icc 2021)

◆ yyjson_has_include

#define yyjson_has_include (   x)    0

include check (since gcc 5.0, clang 2.7, icc 16, msvc 2017 15.3)

◆ yyjson_inline

#define yyjson_inline

inline for compiler

◆ yyjson_likely

#define yyjson_likely (   expr)    (expr)

likely for compiler

◆ YYJSON_MSC_VER

#define YYJSON_MSC_VER   0

compiler version (MSVC)

◆ yyjson_mut_arr_foreach

#define yyjson_mut_arr_foreach (   arr,
  idx,
  max,
  val 
)
Value:
for ((idx) = 0, \
(max) = yyjson_mut_arr_size(arr), \
(val) = yyjson_mut_arr_get_first(arr); \
(idx) < (max); \
(idx)++, \
(val) = (val)->next)
yyjson_api_inline size_t yyjson_mut_arr_size(yyjson_mut_val *arr)
Definition: yyjson.h:4242
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_get_first(yyjson_mut_val *arr)
Definition: yyjson.h:4256

Macro for iterating over an array. It works like iterator, but with a more intuitive API.

Warning
You should not modify the array while iterating over it.
Example
size_t idx, max;
yyjson_mut_arr_foreach(arr, idx, max, val) {
your_func(idx, val);
}
#define yyjson_mut_arr_foreach(arr, idx, max, val)
Definition: yyjson.h:1989

◆ yyjson_mut_obj_foreach

#define yyjson_mut_obj_foreach (   obj,
  idx,
  max,
  key,
  val 
)
Value:
for ((idx) = 0, \
(max) = yyjson_mut_obj_size(obj), \
(key) = (max) ? ((yyjson_mut_val *)(obj)->uni.ptr)->next->next : NULL, \
(val) = (key) ? (key)->next : NULL; \
(idx) < (max); \
(idx)++, \
(key) = (val)->next, \
(val) = (key)->next)
yyjson_api_inline size_t yyjson_mut_obj_size(yyjson_mut_val *obj)
Definition: yyjson.h:4885

Macro for iterating over an object. It works like iterator, but with a more intuitive API.

Warning
You should not modify the object while iterating over it.
Example
size_t idx, max;
yyjson_val *key, *val;
yyjson_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}
#define yyjson_obj_foreach(obj, idx, max, key, val)
Definition: yyjson.h:1597

◆ yyjson_noinline

#define yyjson_noinline

noinline for compiler

◆ yyjson_obj_foreach

#define yyjson_obj_foreach (   obj,
  idx,
  max,
  key,
  val 
)
Value:
for ((idx) = 0, \
(max) = yyjson_obj_size(obj), \
(key) = (obj) ? unsafe_yyjson_get_first(obj) : NULL, \
(val) = (key) + 1; \
(idx) < (max); \
(idx)++, \
(key) = unsafe_yyjson_get_next(val), \
(val) = (key) + 1)
yyjson_api_inline size_t yyjson_obj_size(yyjson_val *obj)
Definition: yyjson.h:3709

Macro for iterating over an object. It works like iterator, but with a more intuitive API.

Example
size_t idx, max;
yyjson_val *key, *val;
yyjson_obj_foreach(obj, idx, max, key, val) {
your_func(key, val);
}

◆ YYJSON_PADDING_SIZE

#define YYJSON_PADDING_SIZE   4

Padding size for JSON reader.

◆ YYJSON_STDC_VER

#define YYJSON_STDC_VER   0

C version (STDC)

◆ YYJSON_TYPE_MASK

#define YYJSON_TYPE_MASK   ((uint8_t)0x07) /* _____111 */

Mask and bits of JSON value.

◆ yyjson_unlikely

#define yyjson_unlikely (   expr)    (expr)

unlikely for compiler

◆ YYJSON_VERSION_HEX

#define YYJSON_VERSION_HEX   0x000500

The version of yyjson in hex: (major << 16) | (minor << 8) | (patch).

◆ YYJSON_VERSION_MAJOR

#define YYJSON_VERSION_MAJOR   0

char bit check The major version of yyjson.

◆ YYJSON_VERSION_MINOR

#define YYJSON_VERSION_MINOR   5

The minor version of yyjson.

◆ YYJSON_VERSION_PATCH

#define YYJSON_VERSION_PATCH   0

The patch version of yyjson.

◆ YYJSON_VERSION_STRING

#define YYJSON_VERSION_STRING   "0.5.0"

The version string of yyjson.

Typedef Documentation

◆ yyjson_read_code

typedef uint32_t yyjson_read_code

Result code for JSON reader.

◆ yyjson_read_flag

typedef uint32_t yyjson_read_flag

Run-time options for JSON reader.

◆ yyjson_subtype

typedef uint8_t yyjson_subtype

Subtype of JSON value (2 bit).

◆ yyjson_type

typedef uint8_t yyjson_type

Type of JSON value (3 bit).

◆ yyjson_write_code

typedef uint32_t yyjson_write_code

Result code for JSON writer

◆ yyjson_write_flag

typedef uint32_t yyjson_write_flag

Run-time options for JSON writer.

Function Documentation

◆ yyjson_alc_pool_init()

yyjson_api bool yyjson_alc_pool_init ( yyjson_alc alc,
void *  buf,
size_t  size 
)

A pool allocator uses fixed length pre-allocated memory.

This allocator may used to avoid malloc()/memmove() calls. The pre-allocated memory should be held by the caller. The upper limit of memory required to read JSON can be calculated using the yyjson_read_max_memory_usage() function, but the memory required to write JSON cannot be calculated directly.

This is not a general-purpose allocator, and should only be used to read or write single JSON document.

Parameters
alcThe allocator to be initialized. If this parameter is NULL, the function will fail and return false. If buf or size is invalid, this parameter is left unmodified.
bufThe buffer memory for this allocator. If this parameter is NULL, the function will fail and return false.
sizeThe 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.
Returns
true if the alc has been successfully initialized.
Example
// parse JSON with stack memory
char buf[1024];
yyjson_alc_pool_init(&alc, buf, 1024);
const char *json = "{\"name\":\"Helvetica\",\"size\":16}"
yyjson_doc *doc = yyjson_read_opts(json, strlen(json), 0, &alc, NULL);
// the memory of `doc` is on the stack
Definition: yyjson.h:474
yyjson_api bool yyjson_alc_pool_init(yyjson_alc *alc, void *buf, size_t size)
yyjson_api yyjson_doc * yyjson_read_opts(char *dat, size_t len, yyjson_read_flag flg, const yyjson_alc *alc, yyjson_read_err *err)
Definition: yyjson.h:3271

◆ yyjson_arr_get()

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.

Warning
This function takes a linear search time if array is not flat. For example: [1,{},3] is flat, [1,[2],3] is not flat.

◆ yyjson_arr_get_first()

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

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.

Warning
This function takes a linear search time if array is not flat. For example: [1,{},3] is flat, [1,[2],3] is not flat.

◆ yyjson_arr_iter_has_next()

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

yyjson_api_inline bool yyjson_arr_iter_init ( yyjson_val arr,
yyjson_arr_iter iter 
)

Initialize an iterator for this array.

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

◆ yyjson_arr_iter_next()

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

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

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

yyjson_api_inline yyjson_val * yyjson_doc_get_pointer ( yyjson_doc doc,
const char *  ptr 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a null-terminated UTF-8 string.

Returns NULL if there's no matched value.

◆ yyjson_doc_get_pointern()

yyjson_api_inline yyjson_val * yyjson_doc_get_pointern ( yyjson_doc doc,
const char *  ptr,
size_t  len 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a UTF-8 string, null-terminator is not required. The len should be the length of the ptr, in bytes.

Returns NULL if there's no matched value.

◆ yyjson_doc_get_read_size()

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

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

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

yyjson_api yyjson_mut_doc * yyjson_doc_mut_copy ( yyjson_doc doc,
const yyjson_alc alc 
)

Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy on the immutable document. If allocator is NULL, the default allocator will be used.

◆ yyjson_equals()

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

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

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

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

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

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

yyjson_api_inline yyjson_val * yyjson_get_pointer ( yyjson_val val,
const char *  ptr 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a null-terminated UTF-8 string.

Returns NULL if there's no matched value. Returns NULL if val/ptr is NULL or val is not object.

◆ yyjson_get_pointern()

yyjson_api_inline yyjson_val * yyjson_get_pointern ( yyjson_val val,
const char *  ptr,
size_t  len 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a UTF-8 string, null-terminator is not required. The len should be the length of the ptr, in bytes.

Returns NULL if there's no matched value. Returns NULL if val/ptr is NULL or val is not object.

◆ yyjson_get_raw()

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

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

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

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

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

yyjson_api_inline uint8_t yyjson_get_tag ( yyjson_val val)

Returns the JSON value's tag. Returns 0 if val is NULL.

◆ yyjson_get_type()

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

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

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

yyjson_api_inline bool yyjson_is_arr ( yyjson_val val)

Returns whether the JSON value is array. Returns false if val is NULL.

◆ yyjson_is_bool()

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

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

yyjson_api_inline bool yyjson_is_false ( yyjson_val val)

Returns whether the JSON value is false. Returns false if val is NULL.

◆ yyjson_is_int()

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

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

yyjson_api_inline bool yyjson_is_obj ( yyjson_val val)

Returns whether the JSON value is object. Returns false if val is NULL.

◆ yyjson_is_raw()

yyjson_api_inline bool yyjson_is_raw ( yyjson_val val)

Returns whether the JSON value is raw. Returns false if val is NULL.

◆ yyjson_is_real()

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

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

yyjson_api_inline bool yyjson_is_str ( yyjson_val val)

Returns whether the JSON value is string. Returns false if val is NULL.

◆ yyjson_is_true()

yyjson_api_inline bool yyjson_is_true ( yyjson_val val)

Returns whether the JSON value is true. Returns false if val is NULL.

◆ yyjson_is_uint()

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

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.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ yyjson_mut_arr()

yyjson_api_inline yyjson_mut_val * yyjson_mut_arr ( yyjson_mut_doc doc)

Creates and returns an empty mutable array.

Parameters
docA mutable document, used for memory allocation only.
Returns
The new array. NULL if input is NULL or memory allocation failed.

◆ yyjson_mut_arr_add_arr()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
The new array, or NULL on error.

◆ yyjson_mut_arr_add_bool()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe bool value to be added.
Returns
Whether successful.

◆ yyjson_mut_arr_add_false()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

◆ yyjson_mut_arr_add_int()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

◆ yyjson_mut_arr_add_null()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

◆ yyjson_mut_arr_add_obj()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
The new object, or NULL on error.

◆ yyjson_mut_arr_add_real()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

◆ yyjson_mut_arr_add_sint()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

◆ yyjson_mut_arr_add_str()

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

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA null-terminated UTF-8 string.
Returns
Whether successful.
Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_arr_add_strcpy()

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

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA null-terminated UTF-8 string.
Returns
Whether successful.

◆ yyjson_mut_arr_add_strn()

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

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA UTF-8 string, null-terminator is not required.
lenThe length of the string, in bytes.
Returns
Whether successful.
Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_arr_add_strncpy()

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

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
strA UTF-8 string, null-terminator is not required.
lenThe length of the string, in bytes.
Returns
Whether successful.

◆ yyjson_mut_arr_add_true()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
Returns
Whether successful.

◆ yyjson_mut_arr_add_uint()

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.

Parameters
docThe doc is only used for memory allocation.
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
numThe number to be added.
Returns
Whether successful.

◆ yyjson_mut_arr_add_val()

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.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

◆ yyjson_mut_arr_append()

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.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

◆ yyjson_mut_arr_clear()

yyjson_api_inline bool yyjson_mut_arr_clear ( yyjson_mut_val arr)

Removes all values in this array.

Parameters
arrThe array from which all of the values are to be removed. Returns false if it is NULL or not an array.
Returns
Whether successful.

◆ yyjson_mut_arr_get()

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.

Warning
This function takes a linear search time.

◆ yyjson_mut_arr_get_first()

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

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

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.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
idxThe index to which to insert the new value. Returns false if the index is out of range.
Returns
Whether successful.
Warning
This function takes a linear search time.

◆ yyjson_mut_arr_iter_has_next()

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

yyjson_api_inline bool yyjson_mut_arr_iter_init ( yyjson_mut_val arr,
yyjson_mut_arr_iter iter 
)

Initialize an iterator for this array.

Parameters
arrThe array to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

◆ yyjson_mut_arr_iter_next()

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

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

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.

Parameters
arrThe array to which the value is to be inserted. Returns false if it is NULL or not an array.
valThe value to be inserted. Returns false if it is NULL.
Returns
Whether successful.

◆ yyjson_mut_arr_remove()

yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove ( yyjson_mut_val arr,
size_t  idx 
)

Removes and returns a value at index.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
idxThe index from which to remove the value. Returns false if the index is out of range.
Returns
Old value, or NULL on error.
Warning
This function takes a linear search time.

◆ yyjson_mut_arr_remove_first()

yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove_first ( yyjson_mut_val arr)

Removes and returns the first value in this array.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
Returns
The first value, or NULL on error.

◆ yyjson_mut_arr_remove_last()

yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_remove_last ( yyjson_mut_val arr)

Removes and returns the last value in this array.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
Returns
The last value, or NULL on error.

◆ yyjson_mut_arr_remove_range()

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.

Parameters
arrThe array from which the value is to be removed. Returns false if it is NULL or not an array.
idxThe start index of the range (0 is the first).
lenThe number of items in the range (can be 0).
Returns
Whether successful.
Warning
This function takes a linear search time.

◆ yyjson_mut_arr_replace()

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.

Parameters
arrThe array to which the value is to be replaced. Returns false if it is NULL or not an array.
idxThe index to which to replace the value. Returns false if the index is out of range.
valThe new value to replace. Returns false if it is NULL.
Returns
Old value, or NULL on error.
Warning
This function takes a linear search time.

◆ yyjson_mut_arr_rotate()

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].

Parameters
arrThe array to be rotated.
idxIndex (or times) to rotate.
Warning
This function takes a linear search time.

◆ yyjson_mut_arr_size()

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

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of boolean values.
countThe value count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const bool vals[3] = { true, false, true };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_bool(yyjson_mut_doc *doc, const bool *vals, size_t count)
Definition: yyjson.h:4371

◆ yyjson_mut_arr_with_double()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of double numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const double vals[3] = { -1.0, 0.0, 1.0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_double(yyjson_mut_doc *doc, const double *vals, size_t count)
Definition: yyjson.h:4465

◆ yyjson_mut_arr_with_float()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of float numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const float vals[3] = { -1.0f, 0.0f, 1.0f };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_float(yyjson_mut_doc *doc, const float *vals, size_t count)
Definition: yyjson.h:4457

◆ yyjson_mut_arr_with_real()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of real numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const double vals[3] = { 0.1, 0.2, 0.3 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_real(yyjson_mut_doc *doc, const double *vals, size_t count)
Definition: yyjson.h:4388

◆ yyjson_mut_arr_with_sint()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of sint numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const int64_t vals[3] = { -1, 0, 1 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint64(yyjson_mut_doc *doc, const int64_t *vals, size_t count)
Definition: yyjson.h:4417

◆ yyjson_mut_arr_with_sint16()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int16 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const int16_t vals[3] = { -1, 0, 1 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint16(yyjson_mut_doc *doc, const int16_t *vals, size_t count)
Definition: yyjson.h:4401

◆ yyjson_mut_arr_with_sint32()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int32 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const int32_t vals[3] = { -1, 0, 1 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint32(yyjson_mut_doc *doc, const int32_t *vals, size_t count)
Definition: yyjson.h:4409

◆ yyjson_mut_arr_with_sint64()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int64 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const int64_t vals[3] = { -1, 0, 1 };

◆ yyjson_mut_arr_with_sint8()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of int8 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const int8_t vals[3] = { -1, 0, 1 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_sint8(yyjson_mut_doc *doc, const int8_t *vals, size_t count)
Definition: yyjson.h:4393

◆ yyjson_mut_arr_with_str()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL.
countThe number of values in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Warning
The input strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. If these strings will be modified, you should use yyjson_mut_arr_with_strcpy() instead.
Example
const char *vals[3] = { "a", "b", "c" };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_str(yyjson_mut_doc *doc, const char **vals, size_t count)
Definition: yyjson.h:4473

◆ yyjson_mut_arr_with_strcpy()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 null-terminator strings. If this array contains NULL, the function will fail and return NULL.
countThe number of values in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const char *vals[3] = { "a", "b", "c" };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_strcpy(yyjson_mut_doc *doc, const char **vals, size_t count)
Definition: yyjson.h:4493

◆ yyjson_mut_arr_with_strn()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL.
lensA C array of string lengths, in bytes.
countThe number of strings in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Warning
The input strings are not copied, you should keep these strings unmodified for the lifetime of this JSON document. If these strings will be modified, you should use yyjson_mut_arr_with_strncpy() instead.
Example
const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3);
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)
Definition: yyjson.h:4483

◆ yyjson_mut_arr_with_strncpy()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of UTF-8 strings, null-terminator is not required. If this array contains NULL, the function will fail and return NULL.
lensA C array of string lengths, in bytes.
countThe number of strings in vals. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const char *vals[3] = { "a", "bb", "c" };
const size_t lens[3] = { 1, 2, 1 };
yyjson_mut_val *arr = yyjson_mut_arr_with_strn(doc, vals, lens, 3);

◆ yyjson_mut_arr_with_uint()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const uint64_t vals[3] = { 0, 1, 0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint(yyjson_mut_doc *doc, const uint64_t *vals, size_t count)
Definition: yyjson.h:4383

◆ yyjson_mut_arr_with_uint16()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint16 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const uint16_t vals[3] = { 0, 1, 0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint16(yyjson_mut_doc *doc, const uint16_t *vals, size_t count)
Definition: yyjson.h:4433

◆ yyjson_mut_arr_with_uint32()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint32 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const uint32_t vals[3] = { 0, 1, 0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint32(yyjson_mut_doc *doc, const uint32_t *vals, size_t count)
Definition: yyjson.h:4441

◆ yyjson_mut_arr_with_uint64()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint64 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const uint64_t vals[3] = { 0, 1, 0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint64(yyjson_mut_doc *doc, const uint64_t *vals, size_t count)
Definition: yyjson.h:4449

◆ yyjson_mut_arr_with_uint8()

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.

Parameters
docA mutable document, used for memory allocation only. If this parameter is NULL, the function will fail and return NULL.
valsA C array of uint8 numbers.
countThe number count. If this value is 0, an empty array will return.
Returns
The new array. NULL if input is invalid or memory allocation failed.
Example
const uint8_t vals[3] = { 0, 1, 0 };
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr_with_uint8(yyjson_mut_doc *doc, const uint8_t *vals, size_t count)
Definition: yyjson.h:4425

◆ yyjson_mut_bool()

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

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

yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_pointer ( yyjson_mut_doc doc,
const char *  ptr 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a null-terminated UTF-8 string.

Returns NULL if there's no matched value.

◆ yyjson_mut_doc_get_pointern()

yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_pointern ( yyjson_mut_doc doc,
const char *  ptr,
size_t  len 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a UTF-8 string, null-terminator is not required. The len should be the length of the ptr, in bytes.

Returns NULL if there's no matched value.

◆ yyjson_mut_doc_get_root()

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

yyjson_api yyjson_mut_doc * yyjson_mut_doc_mut_copy ( yyjson_mut_doc doc,
const yyjson_alc alc 
)

Copies and returns a new mutable document from input, returns NULL on error. This makes a deep-copy on the mutable document. If allocator is NULL, the default allocator will be used.

◆ yyjson_mut_doc_new()

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

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

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.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ yyjson_mut_equals_str()

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

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

yyjson_api_inline yyjson_mut_val * yyjson_mut_false ( yyjson_mut_doc doc)

Creates and returns a false value, returns NULL on error.

◆ yyjson_mut_get_bool()

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

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

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

yyjson_api_inline yyjson_mut_val * yyjson_mut_get_pointer ( yyjson_mut_val val,
const char *  ptr 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a null-terminated UTF-8 string.

Returns NULL if there's no matched value.

◆ yyjson_mut_get_pointern()

yyjson_api_inline yyjson_mut_val * yyjson_mut_get_pointern ( yyjson_mut_val val,
const char *  ptr,
size_t  len 
)

Get a JSON value with JSON Pointer (RFC 6901). The ptr should be a UTF-8 string, null-terminator is not required. The len should be the length of the ptr, in bytes.

Returns NULL if there's no matched value.

◆ yyjson_mut_get_raw()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ yyjson_mut_null()

yyjson_api_inline yyjson_mut_val * yyjson_mut_null ( yyjson_mut_doc doc)

Creates and returns a null value, returns NULL on error.

◆ yyjson_mut_obj()

yyjson_api_inline yyjson_mut_val * yyjson_mut_obj ( yyjson_mut_doc doc)

Creates and returns a mutable object, returns NULL on error.

◆ yyjson_mut_obj_add()

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.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy().
valThe value to add to the object.
Returns
Whether successful.

◆ yyjson_mut_obj_add_bool()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_false()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_int()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_null()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_real()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_sint()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_str()

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.

Warning
The key/value string are not copied, you should keep these strings unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_strcpy()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_strn()

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.

Warning
The key/value string are not copied, you should keep these strings unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_strncpy()

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.

Warning
The key/value string are not copied, you should keep these strings unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_true()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_uint()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_add_val()

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.

Warning
The key string are not copied, you should keep the string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_obj_clear()

yyjson_api_inline bool yyjson_mut_obj_clear ( yyjson_mut_val obj)

Removes all key-value pairs in this object.

Parameters
objThe object from which all of the values are to be removed.
Returns
Whether successful.

◆ yyjson_mut_obj_get()

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.

Warning
This function takes a linear search time.

◆ yyjson_mut_obj_getn()

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.

Warning
This function takes a linear search time.

◆ yyjson_mut_obj_insert()

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.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy().
valThe value to add to the object.
idxThe index to which to insert the new pair.
Returns
Whether successful.

◆ yyjson_mut_obj_iter_get()

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.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

◆ yyjson_mut_obj_iter_get_val()

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

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.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe the length of key, in bytes.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

◆ yyjson_mut_obj_iter_has_next()

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

yyjson_api_inline bool yyjson_mut_obj_iter_init ( yyjson_mut_val obj,
yyjson_mut_obj_iter iter 
)

Initialize an iterator for this object.

Parameters
objThe object to be iterated over. If this parameter is NULL or not an array, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

◆ yyjson_mut_obj_iter_next()

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

yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_iter_remove ( yyjson_mut_obj_iter iter)

Removes and returns current key-value pair in the iteration. If iter is NULL, this function will return NULL.

◆ yyjson_mut_obj_put()

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.

Parameters
objThe object to which the new key-value pair is to be added.
keyThe key, should be a string which is created by yyjson_mut_str(), yyjson_mut_strn(), yyjson_mut_strcpy() or yyjson_mut_strncpy().
valThe value to add to the object. If this value is null, the behavior is same as yyjson_mut_obj_remove().
Returns
Whether successful.

◆ 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.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a string value.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

◆ yyjson_mut_obj_remove_key()

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.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

◆ yyjson_mut_obj_remove_keyn()

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.

Parameters
objThe object from which the key-value pair is to be removed.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe length of the key.
Returns
The first matched value, or NULL if no matched value.
Warning
This function takes a linear search time.

◆ yyjson_mut_obj_remove_str()

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.

Warning
This function takes a linear search time.

◆ yyjson_mut_obj_remove_strn()

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.

Warning
This function takes a linear search time.

◆ yyjson_mut_obj_replace()

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.

Parameters
objThe object to which the value is to be replaced.
keyThe key, should be a string value.
valThe value to replace into the object.
Returns
Whether successful.
Warning
This function takes a linear search time.

◆ yyjson_mut_obj_rotate()

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}.

Parameters
objThe object to be rotated.
idxIndex (or times) to rotate.
Returns
Whether successful.
Warning
This function takes a linear search time.

◆ yyjson_mut_obj_size()

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

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.
Example
const char *kv_pairs[4] = { "id", "01", "name", "Harry" };
yyjson_mut_val *obj = yyjson_mut_obj_with_kv(doc, kv_pairs, 2);
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_with_kv(yyjson_mut_doc *doc, const char **kv_pairs, size_t pair_count)
Definition: yyjson.h:5053

◆ yyjson_mut_obj_with_str()

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.
Example
const char *keys[2] = { "id", "name" };
const char *vals[2] = { "01", "Harry" };
yyjson_mut_val *obj = yyjson_mut_obj_with_str(doc, keys, vals, 2);
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_with_str(yyjson_mut_doc *doc, const char **keys, const char **vals, size_t count)
Definition: yyjson.h:5022

◆ yyjson_mut_raw()

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_rawcpy()

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

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_rawncpy()

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

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

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

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_strcpy()

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

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.

Warning
The input string is not copied, you should keep this string unmodified for the lifetime of this JSON document.

◆ yyjson_mut_strncpy()

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

yyjson_api_inline yyjson_mut_val * yyjson_mut_true ( yyjson_mut_doc doc)

Creates and returns a true value, returns NULL on error.

◆ yyjson_mut_uint()

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

yyjson_api yyjson_mut_val * yyjson_mut_val_mut_copy ( yyjson_mut_doc doc,
yyjson_mut_val val 
)

Copies and return a new mutable value from input, returns NULL on error, This makes a deep-copy on the mutable value. The memory was managed by mutable document.

Warning
This function is recursive and may cause a stack overflow if the object level is too deep.

◆ yyjson_mut_val_write()

yyjson_api_inline char * yyjson_mut_val_write ( const yyjson_mut_val val,
yyjson_write_flag  flg,
size_t *  len 
)

Write a value to JSON string.

This function is thread-safe when: The val is not is not modified by other threads.

Parameters
valThe JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free().

◆ yyjson_mut_val_write_file()

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:

  1. The file is not accessed by other threads.
  2. The val is not modified by other threads.
  3. The alc is thread-safe or NULL.
Parameters
pathThe 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.
valThe mutable JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
true if successful, false if an error occurs.
Warning
On 32-bit operating system, files larger than 2GB may fail to write.

◆ yyjson_mut_val_write_opts()

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:

  1. The val is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
valThe mutable JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free().

◆ yyjson_mut_write()

yyjson_api_inline char * yyjson_mut_write ( const yyjson_mut_doc doc,
yyjson_write_flag  flg,
size_t *  len 
)

Write a document to JSON string.

This function is thread-safe when: The doc is not is not modified by other threads.

Parameters
docThe JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free().

◆ yyjson_mut_write_file()

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:

  1. The file is not accessed by other threads.
  2. The doc is not modified by other threads.
  3. The alc is thread-safe or NULL.
Parameters
pathThe 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.
docThe mutable JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
true if successful, false if an error occurs.
Warning
On 32-bit operating system, files larger than 2GB may fail to write.

◆ yyjson_mut_write_opts()

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:

  1. The doc is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
docThe mutable JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free().

◆ yyjson_obj_get()

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.

Warning
This function takes a linear search time.

◆ yyjson_obj_getn()

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.

Warning
This function takes a linear search time.

◆ yyjson_obj_iter_get()

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.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string with null-terminator.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

◆ yyjson_obj_iter_get_val()

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

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.

Parameters
iterThe object iterator, should not be NULL.
keyThe key, should be a UTF-8 string, null-terminator is not required.
key_lenThe the length of key, in bytes.
Returns
The value to which the specified key is mapped. NULL if this object contains no mapping for the key or input is invalid.
Warning
This function takes a linear search time if the key is not nearby.

◆ yyjson_obj_iter_has_next()

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

yyjson_api_inline bool yyjson_obj_iter_init ( yyjson_val obj,
yyjson_obj_iter iter 
)

Initialize an iterator for this object.

Parameters
objThe object to be iterated over. If this parameter is NULL or not an object, iter will be set to empty.
iterThe iterator to be initialized. If this parameter is NULL, the function will fail and return false.
Returns
true if the iter has been successfully initialized.
Note
The iterator does not need to be destroyed.

◆ yyjson_obj_iter_next()

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

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

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.

Parameters
datThe JSON data (UTF-8 without BOM), null-terminator is not required. If this parameter is NULL, the function will fail and return NULL.
lenThe length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL.
flgThe JSON read options. Multiple options can be combined with | operator. 0 means no options.
Returns
A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with yyjson_doc_free().

◆ yyjson_read_file()

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:

  1. The file is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
pathThe JSON file's path. If this path is NULL or invalid, the function will fail and return NULL.
flgThe JSON read options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with yyjson_doc_free().
Warning
On 32-bit operating system, files larger than 2GB may fail to read.

◆ yyjson_read_max_memory_usage()

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.

Parameters
lenThe length of JSON data in bytes.
flgThe JSON read options.
Returns
The maximum memory size to read this JSON, or 0 if overflow.
Example
// read multiple JSON with same pre-allocated memory
char *dat1, *dat2, *dat3; // JSON data
size_t len1, len2, len3; // JSON length
size_t max_len = MAX(len1, MAX(len2, len3));
// use one allocator for multiple JSON
size_t size = yyjson_read_max_memory_usage(max_len, 0);
void *buf = malloc(size);
yyjson_alc_pool_init(&alc, buf, size);
// no more alloc() or realloc() call during reading
doc = yyjson_read_opts(dat1, len1, 0, &alc, NULL);
doc = yyjson_read_opts(dat2, len2, 0, &alc, NULL);
doc = yyjson_read_opts(dat3, len3, 0, &alc, NULL);
free(buf);
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc)
Definition: yyjson.h:3454
yyjson_api_inline size_t yyjson_read_max_memory_usage(size_t len, yyjson_read_flag flg)
Definition: yyjson.h:782
See also
yyjson_alc_pool_init()

◆ yyjson_read_opts()

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:

  1. The dat is not modified by other threads.
  2. The alc is thread-safe or NULL.
Parameters
datThe 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.
lenThe length of JSON data in bytes. If this parameter is 0, the function will fail and return NULL.
flgThe JSON read options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON reader. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON document, or NULL if an error occurs. When it's no longer needed, it should be freed with yyjson_doc_free().

◆ yyjson_val_mut_copy()

yyjson_api yyjson_mut_val * yyjson_val_mut_copy ( yyjson_mut_doc doc,
yyjson_val val 
)

Copies and returns a new mutable value from input, returns NULL on error. This makes a deep-copy on the immutable value. The memory was managed by mutable document.

◆ yyjson_val_write()

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.

Parameters
valThe JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free().

◆ yyjson_val_write_file()

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:

  1. The file is not accessed by other threads.
  2. The alc is thread-safe or NULL.
Parameters
pathThe 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.
valThe JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
true if successful, false if an error occurs.
Warning
On 32-bit operating system, files larger than 2GB may fail to write.

◆ yyjson_val_write_opts()

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.

Parameters
valThe JSON root value. If this parameter is NULL, the function will fail and return NULL.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free().

◆ yyjson_version()

yyjson_api uint32_t yyjson_version ( void  )

The version of yyjson in hex, same as YYJSON_VERSION_HEX.

◆ yyjson_write()

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.

Parameters
docThe JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free().

◆ yyjson_write_file()

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:

  1. The file is not accessed by other threads.
  2. The alc is thread-safe or NULL.
Parameters
pathThe 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.
docThe JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
true if successful, false if an error occurs.
Warning
On 32-bit operating system, files larger than 2GB may fail to write.

◆ yyjson_write_opts()

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.

Parameters
docThe JSON document. If this doc is NULL or has no root, the function will fail and return false.
flgThe JSON write options. Multiple options can be combined with | operator. 0 means no options.
alcThe memory allocator used by JSON writer. Pass NULL to use the libc's default allocator.
lenA pointer to receive output length in bytes. Pass NULL if you don't need length information.
errA pointer to receive error information. Pass NULL if you don't need error information.
Returns
A new JSON string, or NULL if an error occurs. This string is encoded as UTF-8 with a null-terminator. When it's no longer needed, it should be freed with free() or alc->free().

Variable Documentation

◆ YYJSON_READ_ALLOW_COMMENTS

const yyjson_read_flag YYJSON_READ_ALLOW_COMMENTS = 1 << 3
static

Allow C-style single line and multiple line comments (non-standard).

◆ YYJSON_READ_ALLOW_INF_AND_NAN

const yyjson_read_flag YYJSON_READ_ALLOW_INF_AND_NAN = 1 << 4
static

Allow inf/nan number and literal, case-insensitive, such as 1e999, NaN, inf, -Infinity (non-standard).

◆ YYJSON_READ_ALLOW_INVALID_UNICODE

const yyjson_read_flag YYJSON_READ_ALLOW_INVALID_UNICODE = 1 << 6
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.

Warning
Strings in JSON values may contain incorrect encoding when this option is used, you need to handle these strings carefully to avoid security risks.

◆ YYJSON_READ_ALLOW_TRAILING_COMMAS

const yyjson_read_flag YYJSON_READ_ALLOW_TRAILING_COMMAS = 1 << 2
static

Allow single trailing comma at the end of an object or array, such as [1,2,3,] {"a":1,"b":2,} (non-standard).

◆ YYJSON_READ_ERROR_EMPTY_CONTENT

const yyjson_read_code YYJSON_READ_ERROR_EMPTY_CONTENT = 3
static

Input JSON string is empty.

◆ YYJSON_READ_ERROR_FILE_OPEN

const yyjson_read_code YYJSON_READ_ERROR_FILE_OPEN = 12
static

Failed to open a file.

◆ YYJSON_READ_ERROR_FILE_READ

const yyjson_read_code YYJSON_READ_ERROR_FILE_READ = 13
static

Failed to read a file.

◆ YYJSON_READ_ERROR_INVALID_COMMENT

const yyjson_read_code YYJSON_READ_ERROR_INVALID_COMMENT = 8
static

Invalid comment, such as unclosed multi-line comment.

◆ YYJSON_READ_ERROR_INVALID_NUMBER

const yyjson_read_code YYJSON_READ_ERROR_INVALID_NUMBER = 9
static

Invalid number, such as "123.e12", "000".

◆ YYJSON_READ_ERROR_INVALID_PARAMETER

const yyjson_read_code YYJSON_READ_ERROR_INVALID_PARAMETER = 1
static

Invalid parameter, such as NULL string or invalid file path.

◆ YYJSON_READ_ERROR_INVALID_STRING

const yyjson_read_code YYJSON_READ_ERROR_INVALID_STRING = 10
static

Invalid string, such as invalid escaped character inside a string.

◆ YYJSON_READ_ERROR_JSON_STRUCTURE

const yyjson_read_code YYJSON_READ_ERROR_JSON_STRUCTURE = 7
static

Invalid JSON structure, such as "[1,]".

◆ YYJSON_READ_ERROR_LITERAL

const yyjson_read_code YYJSON_READ_ERROR_LITERAL = 11
static

Invalid JSON literal, such as "truu".

◆ YYJSON_READ_ERROR_MEMORY_ALLOCATION

const yyjson_read_code YYJSON_READ_ERROR_MEMORY_ALLOCATION = 2
static

Memory allocation failure occurs.

◆ YYJSON_READ_ERROR_UNEXPECTED_CHARACTER

const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CHARACTER = 6
static

Unexpected character inside the document, such as "[#]".

◆ YYJSON_READ_ERROR_UNEXPECTED_CONTENT

const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_CONTENT = 4
static

Unexpected content after document, such as "[1]#".

◆ YYJSON_READ_ERROR_UNEXPECTED_END

const yyjson_read_code YYJSON_READ_ERROR_UNEXPECTED_END = 5
static

Unexpected ending, such as "[123".

◆ YYJSON_READ_INSITU

const yyjson_read_flag YYJSON_READ_INSITU = 1 << 0
static

Read the input data in-situ. This option allows the reader to modify and use input data to store string values, which can increase reading speed slightly. The caller should hold the input data before free the document. The input data must be padded by at least YYJSON_PADDING_SIZE bytes. For example: "[1,2]" should be "[1,2]\0\0\0\0", length should be 5.

◆ YYJSON_READ_NOFLAG

const yyjson_read_flag YYJSON_READ_NOFLAG = 0 << 0
static

Default option (RFC 8259 compliant):

  • Read positive integer as uint64_t.
  • Read negative integer as int64_t.
  • Read floating-point number as double with round-to-nearest mode.
  • Read integer which cannot fit in uint64_t or int64_t as double.
  • Report error if real number is infinity.
  • Report error if string contains invalid UTF-8 character or BOM.
  • Report error on trailing commas, comments, inf and nan literals.

◆ YYJSON_READ_NUMBER_AS_RAW

const yyjson_read_flag YYJSON_READ_NUMBER_AS_RAW = 1 << 5
static

Read number as raw string (value with YYJSON_TYPE_RAW type), inf/nan literal is also read as raw with ALLOW_INF_AND_NAN flag.

◆ YYJSON_READ_STOP_WHEN_DONE

const yyjson_read_flag YYJSON_READ_STOP_WHEN_DONE = 1 << 1
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.

◆ YYJSON_READ_SUCCESS

const yyjson_read_code YYJSON_READ_SUCCESS = 0
static

Success, no error.

◆ YYJSON_WRITE_ALLOW_INF_AND_NAN

const yyjson_write_flag YYJSON_WRITE_ALLOW_INF_AND_NAN = 1 << 3
static

Write inf and nan number as 'Infinity' and 'NaN' literal (non-standard).

◆ YYJSON_WRITE_ALLOW_INVALID_UNICODE

const yyjson_read_flag YYJSON_WRITE_ALLOW_INVALID_UNICODE = 1 << 5
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.

◆ YYJSON_WRITE_ERROR_FILE_OPEN

const yyjson_write_code YYJSON_WRITE_ERROR_FILE_OPEN = 5
static

Failed to open a file.

◆ YYJSON_WRITE_ERROR_FILE_WRITE

const yyjson_write_code YYJSON_WRITE_ERROR_FILE_WRITE = 6
static

Failed to write a file.

◆ YYJSON_WRITE_ERROR_INVALID_PARAMETER

const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_PARAMETER = 1
static

Invalid parameter, such as NULL document.

◆ YYJSON_WRITE_ERROR_INVALID_STRING

const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_STRING = 7
static

Invalid unicode in string.

◆ YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE

const yyjson_write_code YYJSON_WRITE_ERROR_INVALID_VALUE_TYPE = 3
static

Invalid value type in JSON document.

◆ YYJSON_WRITE_ERROR_MEMORY_ALLOCATION

const yyjson_write_code YYJSON_WRITE_ERROR_MEMORY_ALLOCATION = 2
static

Memory allocation failure occurs.

◆ YYJSON_WRITE_ERROR_NAN_OR_INF

const yyjson_write_code YYJSON_WRITE_ERROR_NAN_OR_INF = 4
static

NaN or Infinity number occurs.

◆ YYJSON_WRITE_ESCAPE_SLASHES

const yyjson_write_flag YYJSON_WRITE_ESCAPE_SLASHES = 1 << 2
static

Escape '/' as '\/'.

◆ YYJSON_WRITE_ESCAPE_UNICODE

const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE = 1 << 1
static

Escape unicode as uXXXX, make the output ASCII only.

◆ YYJSON_WRITE_INF_AND_NAN_AS_NULL

const yyjson_write_flag YYJSON_WRITE_INF_AND_NAN_AS_NULL = 1 << 4
static

Write inf and nan number as null literal. This flag will override YYJSON_WRITE_ALLOW_INF_AND_NAN flag.

◆ YYJSON_WRITE_NOFLAG

const yyjson_write_flag YYJSON_WRITE_NOFLAG = 0 << 0
static

Default option:

  • Write JSON minify.
  • Report error on inf or nan number.
  • Report error on invalid UTF-8 string.
  • Do not escape unicode or slash.

◆ YYJSON_WRITE_PRETTY

const yyjson_write_flag YYJSON_WRITE_PRETTY = 1 << 0
static

Write JSON pretty with 4 space indent.

◆ YYJSON_WRITE_SUCCESS

const yyjson_write_code YYJSON_WRITE_SUCCESS = 0
static

Success, no error.