stephenberry /glaze
Extremely fast, in memory, serialization, reflection, and RPC library for C++. JSON, BEVE, BSON, CBOR, CSV, JSONB, MessagePack, TOML, YAML, EETF
★ 3,097⑂ 291👁 31▤ 268
3,097
stars
+0+0+35
291
forks
31
watchers
–
prs
–
issues
268
releases
–
discussions
README
Glaze
One of the fastest JSON libraries in the world. Glaze reads and writes from object memory, simplifying interfaces and offering incredible performance.
Formats Supported:
- JSON | glaze/json.hpp
- BEVE (Binary Efficient Versatile Encoding) | glaze/beve.hpp
- CBOR (Concise Binary Object Representation) | glaze/cbor.hpp
- JSONB (SQLite Binary JSON) | glaze/jsonb.hpp
- BSON (MongoDB Binary JSON) | glaze/bson.hpp
- CSV (Comma Separated Value) | glaze/csv.hpp
- MessagePack | glaze/msgpack.hpp
- Stencil/Mustache (string interpolation) | glaze/stencil/stencil.hpp
- TOML 1.1 (Tom's Obvious, Minimal Language) | glaze/toml.hpp
- YAML | glaze/yaml.hpp
- EETF (Erlang External Term Format) | glaze/eetf.hpp
- And Many More Features
[!NOTE]
Glaze is getting HTTP support with REST servers, clients, websockets, and more. The networking side of Glaze is under active development, and while it is usable and feedback is desired, the API is likely to be changing and improving.
With C++23 compile time reflection for MSVC, Clang, and GCC!
- Read/write aggregate initializable structs without writing any metadata or macros!
- See example on Compiler Explorer
C++26 P2996 Reflection Support
Glaze now supports P2996 "Reflection for C++26". When enabled, P2996 unlocks capabilities that aren't possible with traditional compile-time reflection.
P2996 reflection capabilities and examples:
- Non-aggregate types — classes with constructors, virtual functions, and inheritance just work
- Automatic enum serialization — no glz::meta needed, enums serialize to strings automatically
- Unlimited struct members — no 128-member cap
- Private member access — reflect on all members regardless of access specifiers
- Standardized — no compiler-specific hacks, built on std::meta
cpp
// Classes with constructors — just works with P2996
class User {
public:
std::string name;
int age;
User() = default;
User(std::string n, int a) : name(std::move(n)), age(a) {}
};
User u{"Alice", 30};
auto json = glz::write_json(u).value_or("error");
// {"name":"Alice","age":30}
// Enums serialize as strings — no glz::meta required
enum class Color { Red, Green, Blue };
Color c = Color::Green;
struct reflect_enums_opts : glz::opts {
bool reflect_enums = true;
};
auto color_json = glz::write(c).value_or("error");
// "Green"
Supported compilers: GCC 16+ (-std=c++26 -freflection) and Bloomberg clang-p2996. See the P2996 documentation for setup and details.
📖 Documentation
See this README, the Glaze Documentation Page, or docs folder for documentation.
Highlights
- Pure, compile time reflection for structs
- Powerful meta specialization system for custom names and behavior
- C++26 P2996 reflection support — non-aggregates, automatic enums, unlimited members
- JSON RFC 8259 compliance with UTF-8 validation
- Standard C++ library support
- Header only (separate format headers avoid compilation overhead)
- Direct to memory serialization/deserialization
- Compile time ma