|
yyjson 0.13.0
A high performance C JSON library.
|
There are several ways to integrate this library into your project: source code, package manager, and CMake.
This library aims to provide a cross-platform JSON library and targets the ANSI C (C89) standard. It can be compiled with both strict C89 and modern C or C++ compilers. Simply copy yyjson.h and yyjson.c into your project and start using it without any configuration.
The library is tested in GitHub CI with multiple compilers (gcc, clang, msvc, tcc, watcom) and architectures (x86, arm, ppc, riscv, s390x, wasm). Please report a bug if you encounter any compilation issues.
All features are enabled by default, but you can disable some of them with compile-time options. For example, you can disable the JSON writer to reduce binary size when serialization is not needed, or disable comment support to improve parsing performance. See Compile-time Options for details.
You can use some popular package managers like vcpkg, conan, and xmake to download and install yyjson. 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:
Build static library:
Build shared library:
Supported CMake options (default OFF):
You can download and unzip yyjson to your project directory and link it in your CMakeLists.txt file:
If your CMake version is higher than 3.11, you can use the following code to let CMake automatically download it:
If you want to build or debug yyjson with another compiler or IDE, try these commands:
This project uses doxygen to generate the documentation. Make sure doxygen is installed on your system before proceeding, it's best to use the version specified in doc/Doxyfile.in.
To build the documentation:
The generated HTML files will be located in build/doxygen/html.
You can also browse the pre-generated documentation online: https://ibireme.github.io/yyjson/doc/doxygen/html/
Build and run all tests:
Build and run tests with valgrind memory checker, (make sure you have valgrind installed before proceeding):
Build and run tests with sanitizer (address, undefined, or memory) using -DYYJSON_SANITIZER=<name>. For memory, use Clang on Linux x86_64:
Build and run code coverage with gcc:
Build and run code coverage with clang:
Build and run fuzz test with LibFuzzer (compiler should be LLVM Clang, while Apple Clang or gcc are not supported):
This library provides some compile-time options that can be defined as 1 to disable specific features during compilation. For example, to disable the JSON writer:
Define as 1 to disable JSON reader at compile-time.
This disables functions with read in their name.
Reduces binary size by about 60%.
It is recommended when JSON parsing is not required.
Define as 1 to disable JSON writer at compile-time.
This disables functions with write in their name.
Reduces binary size by about 30%.
It is recommended when JSON serialization is not required.
Define as 1 to disable JSON incremental reader at compile-time.
This disables functions with incr in their name.
It is recommended when JSON incremental reader is not required.
Define as 1 to disable file and FILE pointer APIs at compile-time.
stdio.h is not included by yyjson.h when this is set.
Define as 1 to disable JSON Pointer, JSON Patch and JSON Merge Patch support.
This disables functions with ptr or patch in their name.
It is recommended when these functions are not required.
Define as 1 to disable the fast floating-point number conversion in yyjson.
Libc's strtod/snprintf will be used instead.
This reduces binary size by about 30%, but significantly slows down the floating-point read/write speed.
It is recommended when processing JSON with few floating-point numbers.
Define as 1 to disable non-standard JSON features support at compile-time:
This reduces binary size by about 10%, and slightly improves performance.
It is recommended when not dealing with non-standard JSON.
Define as 1 to disable UTF-8 validation at compile-time.
Use this if all input strings are guaranteed to be valid UTF-8 (e.g. language-level String types are already validated).
Disabling UTF-8 validation improves performance for non-ASCII strings by about 3% to 7%.
Note: If this flag is enabled while passing illegal UTF-8 strings, the following errors may occur:
Define as 1 to build yyjson without libc (stdlib.h, string.h, math.h, and stdio.h).
When string.h is unavailable, yyjson provides built-in inline fallbacks for memcpy, memmove, memset, memcmp, and strlen. On modern GCC and Clang at -O2/-O3, these are typically inlined with little impact on throughput. Alternatively, define YYJSON_FREESTANDING_HEADER to a custom header that supplies your own implementations.
malloc and free are not available. Pass a yyjson_alc allocator to each API that accepts one, or define a global default at compile time, for example -DYYJSON_CUSTOM_ALC=my_alc.
File and FILE pointer APIs are also disabled (same effect as YYJSON_DISABLE_FILE). This macro cannot be used together with YYJSON_DISABLE_FAST_FP_CONV.
Intended for freestanding targets such as WebAssembly without a libc sysroot.
Define as a positive integer to set the maximum allowed nesting depth for JSON arrays and objects.
When the parser encounters a container whose depth exceeds this value, it stops and returns the error code YYJSON_READ_ERROR_DEPTH.
The default value is 0, which means unlimited depth is supported. The parser does not use stack recursion, so nesting depth is only bounded by available memory.
Define as a positive integer to set the maximum allowed nesting depth for JSON arrays and objects when writing.
When a document exceeds this depth, writing stops and returns YYJSON_WRITE_ERROR_DEPTH.
The default value is 0, which means unlimited depth is supported. The writer does not use stack recursion, so nesting depth is only bounded by available memory.
Define as 1 to export symbols when building the library as a Windows DLL.
Define as 1 to import symbols when using the library as a Windows DLL.