JSON for Humans.
JSON is great. Until you miss that trailing comma... or want to use comments. What about multiline strings? JSONH provides a much more elegant way to write JSON that's designed for humans rather than machines.
Since JSONH is compatible with JSON, any JSONH syntax can be represented with equivalent JSON.
JsonhCpp is a parser implementation of JSONH v1 for C++.
{
// use #, // or /**/ comments
// quotes are optional
keys: without quotes,
// commas are optional
isn\'t: {
that: cool? # yes
}
// use multiline strings
haiku: '''
Let me die in spring
beneath the cherry blossoms
while the moon is full.
'''
// compatible with JSON5
key: 0xDEADCAFE
// or use JSON
"old school": 1337
}
Everything you need is contained within jsonh_reader
:
#include "jsonh_cpp.hpp" // for jsonh
std::string jsonh = R"(
{
this is: awesome
}
)";
std::string element = jsonh_cpp::jsonh_reader::parse_element<std::string>(jsonh).value();
- C++20
- nlohmann/json (v3.12.0 - patch 2025/07/04 02:33)
- catchorg/Catch2 (v3.9.0) - help
- martinmoene/expected-lite (v0.9.0) - backport
In comparison to JsonhCs, this C++ implementation has some limitations.
The input stream must be in UTF-8 encoding.
If using a different encoding, consider converting to UTF-8 using utfcpp.
Numbers are parsed as long long
and long double
.
In general, these are 64-bit and have a range of about 9 quintillion and a precision of about 15 decimal places.
While tokens can be read one by one from a stream, the tokens are aggregated in a std::vector
before returning due to a lack of yield
in C++.