JSON and FSON Library for C++23
A modern C++23 module-based library for JSON and FSON (Fast JSON) serialization. Built with C++ modules for fast compilation and clean interfaces.
- C++23 compatible compiler (Clang 17+ recommended)
- LLVM with
std.cppmmodule support
The project uses the C++ Builder (CB) build system. From the project root:
tools/CB.sh <path-to-std.cppm> your-program.c++import std;
import xson;
using namespace std::string_literals;
using namespace xson;
auto document = object{};
document["papa"s]["name"s] = "Cool"s;
document["papa"s]["age"s] = 40;
document["papa"s]["married"s] = false;
document["papa"s]["kids"s][1] = { "Name"s, "Tulppu"s };
document["papa"s]["kids"s][2] = { "Name"s, "Elppu"s };
document["papa"s]["kids"s][3] = { "Name"s, "Jalppu"s };
std::clog << json::stringify(document) << std::endl;import std;
import xson;
using namespace std::string_literals;
using namespace xson;
using xson::json::operator <<;
using xson::json::operator >>;
auto ss = std::stringstream{R"(
{
"_id" : 2,
"Name" : "Ruoka",
"Embedded" : {
"_id" : 5,
"Name" : "Tuma"
},
"Lucky Numbers" : [
2,
22,
2112
]
}
)"};
std::clog << ss.str() << "\n\n";
auto result = json::parse(ss);
std::clog << std::setw(2) << result << "\n\n";
std::clog << "_id = " << result["_id"s] << "\n"
<< "Name = " << result["Name"s] << "\n"
<< "Embedded.Name = " << result["Embedded"s]["Name"s] << "\n"
<< "Lucky Number 1 = " << result["Lucky Numbers"s][0] << "\n"
<< "Lucky Number 2 = " << result["Lucky Numbers"s][1] << "\n"
<< "Lucky Number 3 = " << result["Lucky Numbers"s][2] << "\n\n";
xson::integer_type id = result["_id"s];
xson::string_type name = result["Name"s];
xson::integer_type number = result["Lucky Numbers"s][1];The library is organized as C++23 modules:
xson- Main module exporting core types and functionsxson:json- JSON parsing and stringificationxson:fson- FSON (Fast JSON) binary serializationxson:object- Core object, array, and builder typesxson:fast- Fast encoding/decoding utilitiesxson:trace- Debug tracing functionality
- C++23 Modules: Fast compilation with module interfaces
- JSON Support: Full JSON parsing and stringification
- FSON Support: Binary serialization format for efficient storage
- Type-Safe: Strong typing with
integer_type,number_type,string_type, etc. - Extensible: Support for custom types via timestamp and integer types