Skip to content

jsonh-org/JsonhCpp

Repository files navigation

C++

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

JsonhCpp is a parser implementation of JSONH v1 for C++.

Example

{
    // 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
}

Usage

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();

Dependencies

Limitations

In comparison to JsonhCs, this C++ implementation has some limitations.

UTF-8 only

The input stream must be in UTF-8 encoding.

If using a different encoding, consider converting to UTF-8 using utfcpp.

Fixed-size numbers

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.

No token streaming

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

About

JSON for Humans in C++.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages