Yet Another JSON: C++ light-weight JSON parser and formatter
- Single header file, less than 1,500 lines of code
- Supports C++11 and later
- Pure C++: supports Linux, macOS, and Windows
- Supports full RFC 8259 compliance
- With the exception of adopting ECMAScript 6's
\u{XXXXXX}
unicode support - Only generated when Unicode is outside of the supported range for RFC 8259
- Always allowed in parsing
- With the exception of adopting ECMAScript 6's
- Uses dictionary and array semantics as well as methods
- Can create via parsing text or programatically
- Compact or human-readable text formatting available
- Over 90% unit test code coverage
#include "yajson/yajson.h"
#include <iostream>
int main() {
auto json = R"(
{
"test\"me\"": [
1,
2.0,
{"go\/now":3},
{"eol": "\r\n"},
{"ht": "\t"},
{"vt": "\f", "bell": "\b"},
true,
false,
null,
"C:\\"
]
}
)";
auto object = yajson::Value::parse(json);
object["key"] = yajson::Value::object()
.set("real", 3.14)
.set("integer", 42)
.set("null", yajson::Value::null())
.set("list", yajson::Value::array()
.append("JSON Rocks")
.append(true));
std::cout << object.format() << std::endl;
std::cout << std::endl << object.format(2);
return 0;
}
Which produces:
{"key":{"integer":42,"list":["JSON Rocks",true],"null":null,"real":3.140000},"test\"me\"":[1,2.000000,{"go\/now":3},{"eol":"\r\n"},{"ht":"\t"},{"bell":"\b","vt":"\f"},true,false,null,"C:\\"]}
{
"key":{
"integer":42,
"list":[
"JSON Rocks",
true
],
"null":null,
"real":3.140000
},
"test\"me\"":[
1,
2.000000,
{
"go\/now":3
},
{
"eol":"\r\n"
},
{
"ht":"\t"
},
{
"bell":"\b",
"vt":"\f"
},
true,
false,
null,
"C:\\"
]
}