header-only C++20 JSON parser. no dependencies, no external libs, just json.hpp.
#include "json.hpp"
auto v = json::parse(R"({"key": "value", "arr": [1, 2, 3]})");
std::cout << v["key"].as_string() << "\n";
std::cout << v.dump(2) << "\n";drop json.hpp into your project and you're done. everything is in the json namespace.
- null, bool, number, string, array, object
- full unicode escape handling (surrogate pairs)
- pretty-printing with configurable indent
ParseErrorwith position infoValueis a tagged variant, not a tree of void* — type-safe access
g++ -std=c++20 -o test test.cpp && ./test
or pipe json through stdin:
echo '{"hello":"world"}' | ./test
i wanted a json parser that doesn't drag in boost or nlohmann. this is ~340 lines, one header, does the job.