millijson
Lightweight JSON parser for C++
|
millijson is a header-only C++ library that provides a lightweight JSON parser. It has no selling points other than being small and simple, if you could call those selling points. I wrote it mostly for fun but also to provide a replacement for the nlohmann/json
library - while excellent, its single-header source code is pretty large (around 25 kLoCs, if I remember correctly) and I wanted something slimmer. This is most noticeable when vendoring the file into various modules/packages, where C++ suddenly becomes the main language of the associated repository, and I didn't like that. Yes, I'm that petty.
Given a JSON-formatted string:
The same works with a file:
If you just want to validate a file, without using memory to load it:
See the reference documentation for more details.
FetchContent
If you're using CMake, you just need to add something like this to your CMakeLists.txt
:
Then you can link to millijson to make the headers available during compilation:
find_package()
You can install the library by cloning a suitable version of this repository and running the following commands:
Then you can use find_package()
as usual:
If you're not using CMake, the simple approach is to just copy the files in the include/
subdirectory - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I
.
Parsing is based on the JSON standard described here.
This interface was inspired by the implementation in nlohmann/json
.