a modern JSON library for C++20 that's convenient to use
It's not fully finished yet, but it's getting there, and i didn't write documentation beyond the README.md and tests/test.cpp but I'd like some feedback on it.
features
- It's a header only library that's currently < 3000 loc
- no 3rd-party dependencies
- support for being imported as a module
- supports inserting std containers into json nodes
- highly type safe, which is made possible by using concepts
- easy-to-use object/array iterations
- easy-to-use type casting from json value to native c++ types which is enabled by std::variant and concepts
- exception-free parsing and value casting.
- modern error handling using "expected" type
- exception-free node.try_at("key") access
- and more
edit:
documentation link: https://nodeluna.github.io/ljson
https://github.com/nodeluna/ljsonOpen linkView original on programming.dev
Neat! Could you expand on why someone might prefer to use this instead of other json parsing libs such as nlohmann or simdjson?
thank you! if someone wants a more modern API that's kinda similar to tomlplusplus and a little nicer to use with modern error handling then my library might come in handy. my API is inspired a lot by tomlplusplus . i was trying to make a build system that uses TOML as a config file and I needed a json library so i decided to make my own as a learning experience which was great.
I'm not familiar with simdjson, but i know a little about nlohmann and I think the exception free path using ljson::expected is a nicer/safer approach. also there is convenient operator overloads in my library to add objects/array together, but nlohmann also has that i think
** AI GENERATED SHOWCASE THAT'S REVIEWED BY ME **
Here are some cool and advanced features of the ljson library, with short code snippets for each:
You can build JSON objects and arrays directly from standard containers (e.g., std::map, std::vector, std::set, etc.): C++
Concatenate arrays and objects in a natural way:
You can set a node's value using .set() or assignment:
Get error info if you try an invalid conversion:
Any supported type (string, int, bool, null, etc.) or nested containers can be used directly in construction or insertion.
Summary: ljson offers a modern, expressive, and type-safe C++ JSON API with C++ types, safety, and STL integration.