Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 888 Bytes

README.md

File metadata and controls

39 lines (26 loc) · 888 Bytes

cpp-json-parser

header-only C++20 JSON parser. no dependencies, no external libs, just json.hpp.

usage

#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.

features

  • null, bool, number, string, array, object
  • full unicode escape handling (surrogate pairs)
  • pretty-printing with configurable indent
  • ParseError with position info
  • Value is a tagged variant, not a tree of void* — type-safe access

build & test

g++ -std=c++20 -o test test.cpp && ./test

or pipe json through stdin:

echo '{"hello":"world"}' | ./test

why

i wanted a json parser that doesn't drag in boost or nlohmann. this is ~340 lines, one header, does the job.