Welcome to the jsonbench documentation.
The purpose of this tool is to compare the performance of different JSON C/C++ libraries and to show what to expect from a possible alternative JSON processor.
Currently, mod_security2 and libmodsecurity3 use YAJL for JSON processing. Unfortunately, this library is deprecated and no longer maintained.
The tool currently supports the following JSON parsers:
- YAJL
- RAPIDJSON
- NLOHMANNJSON
- JSONC
- JANSSON
- CJSON
- JSONCPP
- JSONCONS
- SIMDJSON
- YYJSON
- GLAZE = It is only compatible with C++23 or newer and is therefore not entirely suitable for modsecurity as it is based on C++17.
You can list them via:
src/jsonbench -hTo compile the code, you need development packages (-dev) of the JSON libraries.
sudo apt install \
libyajl-dev \
rapidjson-dev \
nlohmann-json3-dev \
libjson-c-dev \
libjansson-dev \
libcjson-dev \
libjsoncpp-dev \
libsimdjson-dev \
libyyjson-dev \
libjsoncons-dev \
libglaze-devNote:
- The
-devpackages are required for compiling (headers, pkg-config, etc.) - Runtime libraries (e.g.
libjsoncpp26,libsimdjson25, etc.) are installed automatically
Some packages depend on your distribution version.
Especially:
- libglaze-dev is only available in newer Linux distributions
- Older systems may not provide it
You can check availability with:
apt list | grep glazeor
apt search libglaze-devThese parsers are header-only:
- RapidJSON (
rapidjson-dev) - nlohmann JSON (
nlohmann-json3-dev)
They do not require linking against a library.
./autogen.sh
./configure
make./configure optionally with --with-all-json=yes. This option requires all supported JSON libraries to be available and causes configuration to fail if any are missing.
If you want to disable a parser:
./configure --with-yajl=noShow help:
src/jsonbench -hRun with a specific parser:
src/jsonbench -e YAJLExample:
src/jsonbench -e SIMDJSON -s tests/test01.json-hShow help-eSelect JSON engine-dMax depth (default: 500)-aMax arguments (default: 500)-nNumber of timed iterations (default: 1); reports mean ± stddev across all runs-sSilent mode
Single run:
src/jsonbench -s -e YAJL -a 10000 tests/test06.jsonOutput:
Time: 0.000092567 sec
Multiple iterations (reports mean ± stddev):
src/jsonbench -s -n 20 -e SIMDJSON -a 10000 tests/test06.jsonOutput:
Time: mean=0.000091234 sec stddev=0.000002345 sec (N=20)
Run the test suite:
tests/run_tests.sh # all available engines
tests/run_tests.sh SIMDJSON # single engine- Improve documentation for all parsers
- Add more JSON processors