diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dd4d19..49b0921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. +## 0.6.0 (2022-12-12) +#### Added +- Add functions to modify the content of a JSON value, for example `yyjson_set_int(yyjson_val *val, int num)`. +- Add functions to copy from mutable doc to immutable doc. +- Add functions to support renaming an object's key. +- Add the `yyjson_read_number()` function to parse numeric strings. +- Add a placeholder allocator if `yyjson_alc_pool_init()` fails. + +#### Fixed +- Fix quite NaN on MIPS and HPPA arch. +- Fixed compile error before `GCC 4.5` which doesn't support empty optional extended asm label. +- When built-in floating point conversion is disabled, sprintf() output for floating point numbers is missing a decimal point, for example 123 should be 123.0. + + ## 0.5.1 (2022-06-17) #### Fixed - Fix run-time error when compiling as cpp and 32-bit (g++-5 -m32 -fPIC) #85 diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c4ab0..b69d6e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ # https://github.com/ibireme/yyjson/blob/master/LICENSE cmake_minimum_required(VERSION 3.5) -project(yyjson VERSION 0.5.1) +project(yyjson VERSION 0.6.0) diff --git a/doc/doxygen/html/annotated.html b/doc/doxygen/html/annotated.html index 6c392ff..6502f07 100644 --- a/doc/doxygen/html/annotated.html +++ b/doc/doxygen/html/annotated.html @@ -35,7 +35,7 @@
int64
, uint64
and double
numbers accurately.\u0000
and non null-terminated string.\u0000
and non null-terminated string.h
and one c
file, easy to integrate.All notable changes to this project will be documented in this file.
-yyjson_set_int(yyjson_val *val, int num)
.yyjson_read_number()
function to parse numeric strings.yyjson_alc_pool_init()
fails.GCC 4.5
which doesn't support empty optional extended asm label.YYJSON_READ_NUMBER_AS_RAW
option and RAW
type support.YYJSON_READ_ALLOW_INVALID_UNICODE
and YYJSON_WRITE_ALLOW_INVALID_UNICODE
options to allow invalid unicode.yyjson_mut_obj_remove()
return type from bool
to yyjson_mut_val *
.YYJSON_DISABLE_NON_STANDARD
flag: #80YYJSON_WRITE_INF_AND_NAN_AS_NULL
flag for JSON writer.yyjson_obj_iter_get()
and yyjson_mut_obj_iter_get()
function for faster object search.yyjson_version()
function.YYJSON_DISABLE_COMMENT_READER
and YYJSON_DISABLE_INF_AND_NAN_READER
with YYJSON_DISABLE_NON_STANDARD
compiler flag.YYJSON_DISABLE_FP_READER
and YYJSON_DISABLE_FP_WRITER
with YYJSON_DISABLE_FAST_FP_CONV
compiler flag.-Wconversion
JSON Pointer
support.YYJSON_READ_FASTFP
compiler flag.All public functions and structs are prefixed with yyjson_
, and all constants are prefixed with YYJSON_
.
yyjson have 2 types of data structures: immutable and mutable:
+The library have 2 types of data structures: immutable and mutable:
type | immutable | mutable |
---|---|---|
JSON value | yyjson_val | yyjson_mut_val | document | yyjson_doc | yyjson_mut_doc |
JSON document | yyjson_doc | yyjson_mut_doc | value | yyjson_val | yyjson_mut_val |
When reading a JSON, yyjson returns immutable document and values;
- When building a JSON, yyjson creates mutable document and values;
- The document holds memory for all its JSON values and strings.
+
When reading a JSON, yyjson returns immutable documents and values;
+ When building a JSON, yyjson creates mutable documents and values;
+ The document holds the memory for all its JSON values and strings.
For most immutable APIs, you can just add a mut
after yyjson_
to get the mutable version, for example:
yyjson also provides some functions to convert immutable into mutable:
+
The library also provides some functions to convert values between immutable and mutable:
yyjson supports strings with or without null-terminator.
- When you need to use a non null-terminated string, or you know the length of the string explicitly, you can use a function that ends with n
, for example:
The library supports strings with or without null-terminator ('\0').
+ When you need to use a string without null terminator, or you know the length of the string explicitly, you can use the function that ends with n
, for example:
When creating JSON, yyjson treats strings as constants for better performance. When your string will be modified, you should use a function with a cpy
to copy the string to the document, for example:
yyjson provides 3 methods for reading JSON,
- each method accepts an input of UTF-8 data or file,
- returns a document if succeeds, or returns NULL if fails.
The library provides 3 functions for reading JSON,
+ each function accepts an input of UTF-8 data or a file,
+ returns a document if it succeeds or returns NULL if it fails.
The dat
should be a UTF-8 string, null-terminator is not required.
The len
is the byte length of dat
.
@@ -176,15 +181,15 @@
Sample code:
The path
is JSON file path.
The flg
is reader flag, pass 0 if you don't need it, see reader flag
for details.
@@ -193,15 +198,16 @@
NULL
is returned.
Sample code:
The dat
should be a UTF-8 string, you can pass a const string if you don't use YYJSON_READ_INSITU
flag.
The len
is the dat
's length in bytes.
@@ -212,7 +218,7 @@
Sample code:
@@ -221,19 +227,19 @@yyjson provides a set of flags for JSON reader.
+
The library provides a set of flags for JSON reader.
You can use a single flag, or combine multiple flags with bitwise |
operator.
● YYJSON_READ_NOFLAG
+
● YYJSON_READ_NOFLAG = 0
This is the default flag for JSON reader (RFC-8259 or ECMA-404 compliant):
● YYJSON_READ_INSITU
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
byte. For example: "[1,2]" should be "[1,2]\0\0\0\0", length should be 5.
YYJSON_PADDING_SIZE
byte. For example: [1,2]
should be [1,2]\0\0\0\0
, input length should be 5.
Sample code:
● YYJSON_READ_STOP_WHEN_DONE
Stop when done instead of issues an error if there's additional content after a JSON document.
This option may used to parse small pieces of JSON in larger data, such as NDJSON.
Sample code:
-● YYJSON_READ_ALLOW_TRAILING_COMMAS
Allow single trailing comma at the end of an object or array, for example:
● YYJSON_READ_NUMBER_AS_RAW
Read numbers as raw strings without parsing, allowing you to keep arbitrarily large numbers.
You can use these functions to extract raw strings:
You can use these functions to extract raw strings:
● YYJSON_READ_ALLOW_INVALID_UNICODE
Allow reading invalid unicode when parsing string values (non-standard), for example:
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 provides 3 methods for writing JSON,
- each method accepts an input of JSON document or root value, returns a UTF-8 string or file.
The library provides 3 sets of functions for writing JSON,
+ each function accepts an input of JSON document or root value, and returns a UTF-8 string or file.
The doc/val
is JSON document or root value, if you pass NULL, you will get NULL result.
The flg
is writer flag, pass 0 if you don't need it, see writer flag
for details.
@@ -335,22 +345,23 @@
Sample code 1:
Sample code 2:
The path
is output JSON file path, If the path is invalid, you will get an error. If the file is not empty, the content will be discarded.
The doc/val
is JSON document or root value, if you pass NULL, you will get an error.
@@ -374,39 +385,24 @@
err
is a pointer to receive error message, pass NULL if you don't need it.Sample code:
The doc/val
is JSON document or root value, if you pass NULL, you will get NULL result.
The flg
is writer flag, pass 0 if you don't need it, see writer flag
for details.
@@ -417,29 +413,13 @@
This function returns a new JSON string, or NULL if error occurs.
The string is encoded as UTF-8 with a null-terminator.
You should use free() or alc->free() to release it when it's no longer needed.
yyjson provides a set of flags for JSON writer.
+
The library provides a set of flags for JSON writer.
You can use a single flag, or combine multiple flags with bitwise |
operator.
● YYJSON_WRITE_NOFLAG = 0
This is the default flag for JSON writer:
● YYJSON_WRITE_ALLOW_INF_AND_NAN
- Write inf/nan number as Infinity
and NaN
literals.
- Note that this output is NOT standard JSON and may be rejected by other JSON libraries, for example:
Infinity
and NaN
literals instead of reporting errors.Note that this output is NOT standard JSON and may be rejected by other JSON libraries, for example:
+● YYJSON_WRITE_INF_AND_NAN_AS_NULL
- Write inf/nan number as null
literal.
+ Write inf/nan number as null
literal instead of reporting errors.
This flag will override YYJSON_WRITE_ALLOW_INF_AND_NAN
flag, for example:
● YYJSON_WRITE_ALLOW_INVALID_UNICODE
Allow invalid unicode when encoding string values.
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 \uFFFD
(replacement character).
This flag does not affect the performance of correctly encoded string.
Returns the root value of this JSON document.
Returns read size of input JSON data.
Returns total value count in this JSON document.
Release the JSON document and free the memory.
Returns true if the JSON value is specified type.
- Returns false if the input is NULL
or not the specified type.
-
This set of APIs also have version for mutable values, see mutable and immutable
for details.
You can access the content of a document with the following functions:
A document holds all the memory for its internal values and strings. When you no longer need it, you should release the document and free up all the memory:
Returns the content or type of a JSON value.
- This set of APIs also have version for mutable values, see mutable and immutable
for details.
+JSON Value
+
The following functions can be used to determine the type of a JSON value.
+The following functions can be used to get the contents of the JSON value.
+The following functions can be used to modify the content of a JSON value.
Returns value's type.
Returns value's subtype.
Returns value's tag.
Returns type description, such as: "null", "string", "array", "object", "true", "false", "uint", "sint", "real", "unknown"
Returns bool value, or false if the value is not bool type.
Returns uint value, or 0 if the value is not uint type.
Returns sint value, or 0 if the value is not sint type.
Returns int value (uint may overflow), or 0 if the value is not uint or sint type.
Returns double value, or 0 if the value is not real type.
Returns the string value, or NULL if the value is not string type
Returns the string's length, or 0 if the value is not string type.
Returns whether the value is equals to a string.
Same as `yyjson_equals_str(), but you can pass an explicit string length.
Warning: For immutable documents, these functions will break the immutable
convention, you should use this set of APIs with caution (e.g. make sure the document is only accessed in a single thread).
Returns the property or child value of a JSON array.
- This set of APIs also have version for mutable values, see mutable and immutable
for details.
+JSON Array
+
The following functions can be used to access a JSON array.
Returns the number of elements in this array, or 0 if the input is not an array.
Returns the element at the specified position in this array, or NULL if array is empty or the index is out of bounds.
- Note that this function takes a linear search time if array is not flat.
Returns the first element of this array, or NULL if array is empty.
Returns the last element of this array, or NULL if array is empty.
- Note tha this function takes a linear search time if array is not flat.
Note that accessing elements by an index may take a linear search time. Therefore, if you need to iterate through an array, it is recommended to use the iterator API.
+You can use two methods to traverse an array:
+JSON Array Iterator
+
There are two ways to traverse an array:
Sample code (iterator):
Sample code 1 (iterator API):
Sample code (foreach):
Sample code 2 (foreach macro):
- There's also mutable version API to traverse an mutable array:
Sample code (mutable iterator):
There's also mutable version API to traverse an mutable array:
+
Sample code 1 (mutable iterator API):
Sample code (mutable foreach):
Sample code 2 (mutable foreach macro):
Returns the property or child value of a JSON object.
- This set of APIs also have version for mutable values, see mutable and immutable
for details.
+JSON Object
+
The following functions can be used to access a JSON object.
Returns the number of key-value pairs in this object, or 0 if input is not an object.
Returns the value to which the specified key is mapped,
- or NULL if this object contains no mapping for the key.
- Note that this function takes a linear search time.
Same as `yyjson_obj_get(), but you can pass an explicit string length.
If the order of object's key is known at compile-time, you can use this method to avoid searching the entire object:
Note that accessing elements by a key may take a linear search time. Therefore, if you need to iterate through an object, it is recommended to use the iterator API.
+You can use two methods to traverse an object:
+JSON Object Iterator
+
There are two ways to traverse an object:
Sample code (iterator):
Sample code 1 (iterator API):
Sample code (foreach):
Sample code 2 (foreach macro):
There's also mutable version API to traverse an mutable object:
-Sample code (mutable iterator):
There's also mutable version API to traverse an mutable object:
+
Sample code 1 (mutable iterator API):
Sample code (mutable foreach):
Sample code 2 (mutable foreach macro):
yyjson allows you to query JSON value with JSON Pointer
(RFC 6901).
The library supports querying JSON values via JSON Pointer
(RFC 6901).
For example, given the JSON document:
"/"
You can use a yyjson_mut_doc
to build your JSON document.
+
yyjson_mut_doc
and related APIs are used to build JSON documents.
+
Notice that yyjson_mut_doc
uses a memory pool to hold all strings and values; the pool can only be created, grown, or freed in its entirety. Thus yyjson_mut_doc
is more suitable for write-once than mutation of an existing document.
Notice that yyjson_mut_doc
use a memory pool to hold all strings and values; the pool can only be created, grown or freed in its entirety. Thus yyjson_mut_doc
is more suitable for write-once, than mutation of an existing document.
JSON objects and arrays are made up of linked lists, so each yyjson_mut_val
can only be added to one object or array.
Sample code:
-Creates and returns a new mutable JSON document, returns NULL on error.
- If allocator is NULL, the default allocator will be used. The alc
is memory allocator, pass NULL if you don't need it, see memory allocator
for details.
-
Delete the JSON document, free the memory of this doc (and all values created from this doc).
Get or set the root value of this JSON document.
The following functions are used to create, modify, copy, and destroy a JSON document.
+
Copies and returns a new mutable document from input, returns NULL on error.
- The alc
is memory allocator, pass NULL if you don't need it, see memory allocator
for details.
-
Copies and returns a new mutable value from input, returns NULL on error.
- The memory was managed by document. */
You can use these functions to create mutable JSON value,
- The value's memory is held by the document.
-
+JSON Value Creation
+
The following functions are used to create mutable JSON value, the value's memory is held by the document.
Creates and returns a null value, returns NULL on error.
Creates and returns a true value, returns NULL on error.
Creates and returns a false value, returns NULL on error.
Creates and returns a bool value, returns NULL on error.
Creates and returns an unsigned integer value, returns NULL on error.
Creates and returns a signed integer value, returns NULL on error.
Creates and returns a signed integer value, returns NULL on error.
Creates and returns an real number value, returns NULL on error.
Creates and returns a string value, returns NULL on error.
- The input value should be a valid UTF-8 encoded string with null-terminator.
- Note that the input string is NOT copied.
Creates and returns a string value, returns NULL on error.
- The input value should be a valid UTF-8 encoded string.
- Note that the input string is NOT copied.
Creates and returns a string value, returns NULL on error.
- The input value should be a valid UTF-8 encoded string with null-terminator.
- The input string is copied and held by the document.
Creates and returns a string value, returns NULL on error.
- The input value should be a valid UTF-8 encoded string.
- The input string is copied and held by the document.
Creates and returns an empty mutable array, returns NULL on error.
Creates and returns a mutable array with c array.
The following functions are used to create mutable JSON array.
+
Creates and returns a mutable array with strings. The strings should be encoded as UTF-8.
Inserts a value into an array at a given index, returns false on error.
- Note that Tthis function takes a linear search time.
Inserts a val at the end of the array, returns false on error.
Inserts a val at the head of the array, returns false on error.
Replaces a value at index and returns old value, returns NULL on error.
- Note that this function takes a linear search time.
Removes and returns a value at index, returns NULL on error.
- Note that this function takes a linear search time.
Removes and returns the first value in this array, returns NULL on error.
Removes and returns the last value in this array, returns NULL on error.
Removes all values within a specified range in the array.
- Note that this function takes a linear search time.
Removes all values in this array.
Adds a value at the end of this array, returns false on error.
The following functions are used to modify the contents of a JSON array.
+
Creates and adds a new array at the end of the array.
- Returns the new array, or NULL on error.
Creates and adds a new object at the end of the array.
- Returns the new object, or NULL on error.
Creates and returns a mutable object, returns NULL on error.
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 encoded as UTF-8 with null-terminator.
The following functions are used to create mutable JSON object.
+
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 encoded as UTF-8 with null-terminator.
Adds a key-value pair at the end of the object. The key must be a string.
- This function allows duplicated key in one object.
Adds a key-value pair to the object, The key must be a string.
- This function may remove all key-value pairs for the given key before add.
- Note that this function takes a linear search time.
Removes key-value pair from the object with given key.
- Note that this function takes a linear search time.
Removes all key-value pairs in this object.
Adds a key-value pair at the end of the object. The key is not copied.
- Note that these functions allow duplicated key in one object.
The following functions are used to modify the contents of a JSON object.
+
Removes all key-value pairs for the given key.
- Note that this function takes a linear search time.
Creates and returns a merge-patched JSON value (RFC 7386). Returns NULL if the patch could not be applied. Specification and example: https://tools.ietf.org/html/rfc7386
The library supports JSON Merge Patch (RFC 7386). Specification and example: https://tools.ietf.org/html/rfc7386
yyjson has a built-in high-performance number reader,
+
The library has a built-in high-performance number reader,
it will parse numbers according to these rules by default:
real
number overflow (infinity), it will report an error.You can use YYJSON_READ_ALLOW_INF_AND_NAN
flag to allow nan
and inf
number/literal, see reader flag
for details.
You can use YYJSON_READ_ALLOW_INF_AND_NAN
flag to allow nan
and inf
number/literal. You can also use YYJSON_READ_NUMBER_AS_RAW
to read numbers as raw strings without parsing them. See Reader flag
for details.
yyjson has a built-in high-performance number writer,
+
The library has a built-in high-performance number writer,
it will write numbers according to these rules by default:
You can use YYJSON_WRITE_ALLOW_INF_AND_NAN
flag to write inf/nan number as Infinity
and NaN
literals without error, but this is not standard JSON, see writer flag
for details.
You can also use YYJSON_WRITE_INF_AND_NAN_AS_NULL
to write inf/nan number as null
without error.
You can use YYJSON_WRITE_ALLOW_INF_AND_NAN
flag to write inf/nan number as Infinity
and NaN
literals without error, but this is not standard JSON. You can also use YYJSON_WRITE_INF_AND_NAN_AS_NULL
to write inf/nan number as null
literal. See Writer flag
for details.
yyjson only supports UTF-8 encoding without BOM, as specified in RFC 8259:
+The library only supports UTF-8 encoding without BOM, as specified in RFC 8259:
JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8. Implementations MUST NOT add a byte order mark (U+FEFF) to the beginning of a networked-transmitted JSON text.
By default, yyjson performs a strict UTF-8 encoding validation on input strings. An error will be reported when an invalid character is encountered.
-You could use YYJSON_READ_ALLOW_INVALID_UNICODE
and YYJSON_WRITE_ALLOW_INVALID_UNICODE
flag to allow invalid unicode encoding. However, you should be aware that the result value from yyjson may contain invalid characters, which can be used by other code and may pose security risks.
You could use YYJSON_READ_ALLOW_INVALID_UNICODE
and YYJSON_WRITE_ALLOW_INVALID_UNICODE
flags to allow invalid unicode encoding. However, you should be aware that the result value from yyjson may contain invalid characters, which can be used by other code and may pose security risks.
yyjson supports the NUL
character (also known as null terminator
, or Unicode U+0000
, ASCII \0
).
When reading JSON, \u0000
will be unescaped to NUL
. If a string contains NUL
, the length obtained with strlen() will be inaccurate, and you should use yyjson_get_len() to get the real length.
When building JSON, the input string is treated as null-terminated. If you need to pass in a string with NUL
inside, you should use the API with the n
suffix and pass in the real length.
The library supports the NUL
character (also known as null terminator
, or Unicode U+0000
, ASCII \0
) inside strings.
When reading JSON, \u0000
will be unescaped to NUL
. If a string contains NUL
, the length obtained with strlen() will be inaccurate, and you should use yyjson_get_len() to get the actual length.
When building JSON, the input string is treated as null-terminated. If you need to pass in a string with NUL
inside, you should use the API with the n
suffix and pass in the actual length.
For example:
yyjson does not call libc's memory allocation functions (malloc/realloc/free) directly. When memory allocation is required, yyjson's API takes a parameter named alc
that allows the caller to pass in an allocator. If the alc
is NULL, yyjson will use the default memory allocator, which is a simple wrapper of libc's functions.
The library does not call libc's memory allocation functions (malloc/realloc/free) directly. Instead, when memory allocation is required, yyjson's API takes a parameter named alc
that allows the caller to pass in an allocator. If the alc
is NULL, yyjson will use the default memory allocator, which is a simple wrapper of libc's functions.
Custom memory allocator allows you to take more control over memory allocation, here are a few examples:
-If you need to parse multiple small JSON, you can use a single allocator with pre-allocated buffer to avoid frequent memory allocation.
Sample code:
If the JSON is small enough, you can use stack memory to read or write it.
Sample code:
You can use a third-party high-performance memory allocator for yyjson,
such as jemalloc, tcmalloc, mimalloc.
yyjson's public API will do null check
for every input parameters to avoid crashes.
The library's public API will do null check
for every input parameter to avoid crashes.
For example, when reading a JSON, you don't need to do null check or type check on each value:
But if you are sure that a value is non-null, and the type is matched, you can use the unsafe
prefix API to avoid the null check.
But if you are sure that a value is non-null and the type is matched, you can use the unsafe
prefix API to avoid the null check.
For example, when iterating over an array or object, the value and key must be non-null:
yyjson does not use global variables, so if you can ensure that the input parameters of a function are immutable, then the function call is thread-safe.
+
The library does not use global variables, so if you can ensure that the input parameters of a function are thread-safe, then the function calls are also thread-safe.
yyjson_doc
and yyjson_val
is immutable and thread-safe,
- yyjson_mut_doc
and yyjson_mut_val
is mutable and not thread-safe.
Typically, yyjson_doc
and yyjson_val
are immutable and thread-safe, while yyjson_mut_doc
and yyjson_mut_val
are mutable and not thread-safe.
yyjson is locale-independent.
+The library is locale-independent.
However, there are some special conditions that you need to be aware of:
setlocale()
function to change locale.YYJSON_DISABLE_FAST_FP_CONV
flag at build time.YYJSON_DISABLE_FAST_FP_CONV
during build, in which case yyjson will use strtod()
to parse floating-point numbers.When you meet both of these conditions, you should avoid call setlocale()
while other thread is parsing JSON, otherwise an error may be returned for JSON floating point number parsing.
When you meet both of these conditions, you should avoid calling setlocale()
while other thread is parsing JSON, otherwise an error may be returned for JSON floating point number parsing.
There are several ways to integrate yyjson into your project: source code, package manager, and CMake.
yyjson aims to provide a cross-platform JSON library, so it was written in ANSI C (actually C99, but compatible with strict C89). You can copy yyjson.h
and yyjson.c
to your project and start using it without any configuration.
yyjson aims to provide a cross-platform JSON library, so it is written in ANSI C (actually C99, but compatible with strict C89). You can copy yyjson.h
and yyjson.c
to your project and start using it without any configuration.
yyjson has been tested with the following compilers: gcc
, clang
, msvc
, icc
, tcc
. If you get a compile error, please report a bug.
yyjson has all features enabled by default, but you can trim out some of them by adding compile-time options. For example, disable JSON writer to reduce the binary size when you don't need serialization, or disable comments support to improve parsing performance. See Compile-time Options
for details.
You can use some popular package managers to download and install yyjson, such as vcpkg
, conan
, and xmake
. The yyjson package in these package managers is kept up to date by community contributors. If the version is out of date, please create an issue or pull request on their repository.
You can build and install yyjson using vcpkg dependency manager:
+If the version is out of date, please create an issue or pull request on the vcpkg repository.
+Clone the repository and create build directory:
-DYYJSON_ENABLE_VALGRIND=ON
Enable valgrind memory checker for tests.-DYYJSON_ENABLE_SANITIZE=ON
Enable sanitizer for tests.-DYYJSON_ENABLE_FASTMATH=ON
Enable fast-math for tests.-YYJSON_FORCE_32_BIT=ON
Force 32-bit for tests (gcc/clang/icc).-DYYJSON_FORCE_32_BIT=ON
Force 32-bit for tests (gcc/clang/icc).-DYYJSON_DISABLE_READER=ON
Disable JSON reader if you don't need it.-DYYJSON_DISABLE_WRITER=ON
Disable JSON writer if you don't need it.-DYYJSON_DISABLE_FAST_FP_CONV=ON
Disable fast floating-pointer conversion.-DYYJSON_DISABLE_FAST_FP_CONV=ON
Disable builtin fast floating-pointer conversion.-DYYJSON_DISABLE_NON_STANDARD=ON
Disable non-standard JSON support at compile-time.You may add the yyjson
subdirectory to your CMakeFile.txt, and link it to your target:
You may also add some build options for yyjson library:
You can download and unzip yyjson to your project folder and link it in your CMakeLists.txt
file:
If your CMake version is higher than 3.14, you can use the following method to let CMake automatically download it:
If you want to build or debug yyjson
with another compiler or IDE, try these commands:
yyjson uses doxygen to generate the documentation (you must have doxygen
installed):
After executing this script, doxygen will output the generated html files to build/doxygen/html
. You can also read the pre-generated document online: https://ibireme.github.io/yyjson/doc/doxygen/html/
Build and run all tests:
Build and run fuzz test with LibFuzzer (compiler should be LLVM Clang
, Apple Clang
or gcc
is not supported):
Build and run fuzz test with LibFuzzer (compiler should be LLVM Clang
, while Apple Clang
or gcc
are not supported):
yyjson supports some compile-time options, you can define these macros as 1
to disable some features at compile-time.
● YYJSON_DISABLE_READER
@@ -198,7 +222,7 @@
This will reduce the binary size by about 60%.
It is recommended when you don't need to parse JSON.
● YYJSON_DISABLE_WRITER
@@ -215,28 +239,28 @@
This will reduce the binary size by about 30%.
It is recommended when you don't need to serialize JSON.
● YYJSON_DISABLE_FAST_FP_CONV
Define as 1 to disable the fast floating-point number conversion in yyjson, and use libc's strtod/snprintf
instead.
- This will reduce binary size by about 30%, but significantly slow down floating-point reading and writing speed.
+ This will reduce binary size by about 30%, but significantly slow down the floating-point read/write speed.
It is recommended when you don't need to deal with JSON that contains a lot of floating point numbers.
● YYJSON_DISABLE_NON_STANDARD
Define as 1 to disable non-standard JSON support at compile-time:
NaN
, -Infinity
.This will reduce binary size by about 10%, and increase performance slightly.
It is recommended when you don't need to deal with non-standard JSON.
● YYJSON_EXPORTS
diff --git a/doc/doxygen/html/md_doc__data_structure.html b/doc/doxygen/html/md_doc__data_structure.html
index ac10186..40adf02 100644
--- a/doc/doxygen/html/md_doc__data_structure.html
+++ b/doc/doxygen/html/md_doc__data_structure.html
@@ -35,7 +35,7 @@
yyjson has 2 types of data structures: immutable and mutable.
-When reading a JSON, yyjson returns immutable document and values;
- When building a JSON, yyjson creates mutable document and values.
- yyjson also provides some methods to convert immutable document into mutable document.
-
- Note that the data structures described in this document are private, and you should use public API to access them.
yyjson has two types of data structures: immutable and mutable.
+Note that the data structures described in this document are private, and you should use the public API to access them.
Each JSON value is stored in an immutable yyjson_val
struct:
The lower 8 bits of tag
stores the type of value.
The higher 56 bits of tag
stores the size of value (string length, object size or array size).
Modern 64-bit processors are typically limited to supporting fewer than 64 bits for RAM addresses (Wikipedia). For example, Intel64, AMD64 and ARMv8 has a 52-bit (4PB) physical address limit. So we can safely store type and size into a 64 bits tag
.
Modern 64-bit processors are typically limited to supporting fewer than 64 bits for RAM addresses (Wikipedia). For example, Intel64, AMD64, and ARMv8 have a 52-bit (4PB) physical address limit. Therefore, it is safe to store the type and size in a 64-bit tag
.
A JSON document stores all strings in a contiguous memory area.
Each string is unescaped in-place and ended with a null-terminator.
@@ -131,16 +132,16 @@
A JSON document stores all values in another contiguous memory area.
The object
and array
stores their own memory usage, so we can easily walk through a container's child values.
For example:
Each mutable JSON value is stored in an yyjson_mut_val
struct:
+ + + +
The tag
and uni
field is same as immutable value, the next
field is used to build linked list.
A mutable JSON document is composed of multiple yyjson_mut_val
.
The child values of an object
or array
are linked as a cycle,
- the parent hold the tail of the linked list, so yyjson can do append
, prepend
and remove_first
in O(1) time.
append
, prepend
and remove_first
in O(1) time.
For example:
Build and Test | |
Building and testing | |
API | |
Data Structures | |
Changelog | |
- | diff --git a/doc/doxygen/html/yyjson_8h.html b/doc/doxygen/html/yyjson_8h.html index 155de54..596dea3 100644 --- a/doc/doxygen/html/yyjson_8h.html +++ b/doc/doxygen/html/yyjson_8h.html @@ -35,7 +35,7 @@|
- | @@ -177,13 +177,13 @@|
#define | YYJSON_VERSION_MAJOR 0 |
#define | YYJSON_VERSION_MINOR 5 |
#define | YYJSON_VERSION_MINOR 6 |
#define | YYJSON_VERSION_PATCH 1 |
#define | YYJSON_VERSION_PATCH 0 |
#define | YYJSON_VERSION_HEX 0x000501 |
#define | YYJSON_VERSION_HEX 0x000600 |
#define | YYJSON_VERSION_STRING "0.5.1" |
#define | YYJSON_VERSION_STRING "0.6.0" |
#define | YYJSON_TYPE_MASK ((uint8_t)0x07) /* _____111 */ |
yyjson_api_inline size_t | yyjson_read_max_memory_usage (size_t len, yyjson_read_flag flg) |
yyjson_api const char * | yyjson_read_number (const char *dat, yyjson_val *val, yyjson_read_flag flg, yyjson_read_err *err) |
yyjson_api_inline const char * | yyjson_mut_read_number (const char *dat, yyjson_mut_val *val, yyjson_read_flag flg, yyjson_read_err *err) |
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 bool | yyjson_equals (yyjson_val *lhs, yyjson_val *rhs) |
yyjson_api_inline bool | yyjson_set_raw (yyjson_val *val, const char *raw, size_t len) |
yyjson_api_inline bool | yyjson_set_null (yyjson_val *val) |
yyjson_api_inline bool | yyjson_set_bool (yyjson_val *val, bool num) |
yyjson_api_inline bool | yyjson_set_uint (yyjson_val *val, uint64_t num) |
yyjson_api_inline bool | yyjson_set_sint (yyjson_val *val, int64_t num) |
yyjson_api_inline bool | yyjson_set_int (yyjson_val *val, int num) |
yyjson_api_inline bool | yyjson_set_real (yyjson_val *val, double num) |
yyjson_api_inline bool | yyjson_set_str (yyjson_val *val, const char *str) |
yyjson_api_inline bool | yyjson_set_strn (yyjson_val *val, const char *str, size_t len) |
yyjson_api_inline size_t | yyjson_arr_size (yyjson_val *arr) |
yyjson_api_inline yyjson_val * | yyjson_arr_get (yyjson_val *arr, size_t idx) |
yyjson_api yyjson_mut_val * | yyjson_mut_val_mut_copy (yyjson_mut_doc *doc, yyjson_mut_val *val) |
yyjson_api yyjson_doc * | yyjson_mut_doc_imut_copy (yyjson_mut_doc *doc, const yyjson_alc *alc) |
yyjson_api yyjson_doc * | yyjson_mut_val_imut_copy (yyjson_mut_val *val, const yyjson_alc *alc) |
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_equals (yyjson_mut_val *lhs, yyjson_mut_val *rhs) |
yyjson_api_inline bool | yyjson_mut_set_raw (yyjson_mut_val *val, const char *raw, size_t len) |
yyjson_api_inline bool | yyjson_mut_set_null (yyjson_mut_val *val) |
yyjson_api_inline bool | yyjson_mut_set_bool (yyjson_mut_val *val, bool num) |
yyjson_api_inline bool | yyjson_mut_set_uint (yyjson_mut_val *val, uint64_t num) |
yyjson_api_inline bool | yyjson_mut_set_sint (yyjson_mut_val *val, int64_t num) |
yyjson_api_inline bool | yyjson_mut_set_int (yyjson_mut_val *val, int num) |
yyjson_api_inline bool | yyjson_mut_set_real (yyjson_mut_val *val, double num) |
yyjson_api_inline bool | yyjson_mut_set_str (yyjson_mut_val *val, const char *str) |
yyjson_api_inline bool | yyjson_mut_set_strn (yyjson_mut_val *val, const char *str, size_t len) |
yyjson_api_inline bool | yyjson_mut_set_arr (yyjson_mut_val *val) |
yyjson_api_inline bool | yyjson_mut_set_obj (yyjson_mut_val *val) |
yyjson_api_inline yyjson_mut_val * | yyjson_mut_raw (yyjson_mut_doc *doc, const char *str) |
yyjson_api_inline yyjson_mut_val * | yyjson_mut_rawn (yyjson_mut_doc *doc, const char *str, size_t len) |
yyjson_api_inline yyjson_mut_val * | yyjson_mut_obj_remove_strn (yyjson_mut_val *obj, const char *key, size_t len) |
yyjson_api_inline bool | yyjson_mut_obj_rename_key (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *new_key) |
yyjson_api_inline bool | yyjson_mut_obj_rename_keyn (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, size_t len, const char *new_key, size_t new_len) |
yyjson_api_inline yyjson_val * | yyjson_get_pointer (yyjson_val *val, const char *ptr) |
yyjson_api_inline yyjson_val * | yyjson_get_pointern (yyjson_val *val, const char *ptr, size_t len) |
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_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 |
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.
+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.