Header-only C++17 support for ASON, a schema-driven data format for compact structured payloads.
ASON writes the schema once and stores repeated rows as tuples:
[
{"id": 1, "name": "Alice", "active": true},
{"id": 2, "name": "Bob", "active": false}
][{id@int,name@str,active@bool}]:(1,Alice,true),(2,Bob,false)
That cuts repeated keys, reduces payload size, and keeps typed structure visible.
- Header-only, just
#include "ason.hpp" - Current API uses
encode/decode, not the olderdump/loadnames - Text and binary formats
- SIMD-aware parser and zero-copy-friendly decoding
- Support for
std::optional,std::vector, nested structs, and entry-list collections
#include "ason.hpp"
struct User {
int64_t id = 0;
std::string name;
bool active = false;
};
ASON_FIELDS(User,
(id, "id", "int"),
(name, "name", "str"),
(active, "active", "bool"))User user{1, "Alice", true};
std::string text = ason::encode(user);
// {id,name,active}:(1,Alice,true)
std::string typed = ason::encode_typed(user);
// {id@int,name@str,active@bool}:(1,Alice,true)
User decoded = ason::decode<User>(text);ASON C++ no longer provides a native map/dictionary field syntax. Model key-value data as arrays of entry structs instead:
struct EnvEntry {
std::string key;
std::string value;
};
ASON_FIELDS(EnvEntry,
(key, "key", "str"),
(value, "value", "str"))
struct ServiceConfig {
std::vector<EnvEntry> env;
};std::vector<User> users = {
{1, "Alice", true},
{2, "Bob", false},
};
auto text = ason::encode(users);
// [{id,name,active}]:(1,Alice,true),(2,Bob,false)
auto typed = ason::encode_typed(users);
auto decoded = ason::decode<std::vector<User>>(text);std::string bin = ason::encode_bin(user);
User decoded = ason::decode_bin<User>(bin);| Function | Purpose |
|---|---|
ason::encode / ason::encode_typed |
Encode to text |
ason::decode<T> |
Decode from text |
ason::encode_pretty / ason::encode_pretty_typed |
Pretty text output |
ason::encode_bin |
Encode to binary |
ason::decode_bin<T> |
Decode from binary |
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/basic
./build/complex_example
./build/bench
ctest --test-dir buildason-cpp can now be consumed as a standard header-only CMake package:
find_package(ason CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE ason::ason)The repository ships a ready-to-use conanfile.py.
cd ason-cpp
conan create . --build=missingAn overlay port is included under vcpkg/ports/ason-cpp.
vcpkg install ason-cpp --overlay-ports=/path/to/ason-cpp/vcpkg/portsA formula template is included at homebrew/ason-cpp.rb.
Before publishing to a tap, replace REPLACE_WITH_RELEASE_SHA256 with the actual release tarball hash.
Measured on this machine with:
./build/benchHeadline numbers:
- Flat 1,000-record dataset: ASON text serialize
11.66msvs JSON29.05ms, deserialize34.63msvs JSON44.75ms - Throughput summary: ASON text was
2.49xfaster than JSON for serialize and1.29xfaster for deserialize - Size summary for 1,000 flat records: JSON
121,675 B, ASON text56,718 B(53%smaller), ASON binary74,454 B(39%smaller) - Binary decode was especially strong:
5.97msvs JSON44.75mson flat 1,000-record data, or7.50xfaster
For 100 deep company objects, ASON text serialized 170,183 B vs JSON 431,612 B and decoded 2.45x faster.
MIT