mir-ion
Fast ION binary and JSON serialization for D. Zero-copy parsing, automatic struct serialization via mir-core reflection, BetterC compatible read path.
๐ Full API reference โ mir-ion.libmir.org โ every module and symbol of
mir-ion, regenerated from current source.
mir-ion is a serialization library for D that targets both Amazon Ion (a superset of JSON with a binary format) and plain JSON. Its design priorities are: zero-copy parsing, compile-time auto-generated codecs via mir-core reflection, and @nogc compatibility on the read path.
GitHub: libmir/mir-ion ยท Last commit: November 2025
Install
dependency "mir-ion" version="~>2.0"
dependency "mir-core" version="~>1.0"JSON serialization
Struct โ JSON string
import mir.ion.ser.json : serializeJson;
import mir.ion.deser.json : deserializeJson;
struct Point {
double x;
double y;
string label;
}
auto p = Point(1.5, 2.5, "origin");
string json = p.serializeJson;
// {"x":1.5,"y":2.5,"label":"origin"}JSON string โ struct
auto p2 = deserializeJson!Point(`{"x": 3.0, "y": 4.0, "label": "B"}`);
assert(p2.x == 3.0);Nested structs and arrays
import mir.ndslice : slice;
struct Dataset {
string name;
double[] values;
}
auto ds = Dataset("test", [1.0, 2.0, 3.0]);
string json = ds.serializeJson;
// {"name":"test","values":[1.0,2.0,3.0]}Custom serialization keys
import mir.ion.ser : serdeKeys, serdeIgnore;
struct Config {
@serdeKeys("max_iter", "maxIter")
int maxIterations = 100;
@serdeIgnore
string internalNote;
}ION binary format
ION binary is more compact and faster to parse than JSON. Use it for internal data exchange:
import mir.ion.ser.ion : serializeIon;
import mir.ion.deser.ion : deserializeIon;
ubyte[] binary = p.serializeIon;
auto p3 = deserializeIon!Point(binary);ION binary uses a type-annotated format โ no quoting, no parsing of number strings.
Streaming / zero-copy parsing
For large inputs, parse without building an intermediate DOM:
import mir.ion.value : IonDescribedValue;
import mir.ion.stream : IonStream;
// Iterate over top-level ION values in a stream
foreach (IonDescribedValue v; IonStream(buffer)) {
// process v without full deserialization
}Comparison with std.json and asdf
| Feature | std.json | asdf | mir-ion |
|---|---|---|---|
| Zero-copy | No | No | Yes |
| Binary ION | No | No | Yes |
| Auto struct codec | No | Yes | Yes |
@nogc read | No | No | Yes |
| BetterC | No | No | Yes (read) |
| Custom keys | No | Yes | Yes |
Relationship to mir-core
mir-ion uses mir.reflection (from mir-core) to introspect struct fields at compile time and generate serialization/deserialization code automatically. No macros or separate schema files needed.
Related guides
mir-optim
Optimization algorithms for D โ nonlinear least-squares (Levenberg-Marquardt), L-BFGS, and trust-region methods. Works with ndslice, BetterC compatible.
mir-blas โ BLAS Bindings for D
mir-blas provides BLAS (Basic Linear Algebra Subprograms) bindings for D that accept ndslice directly, enabling high-performance matrix and vector operations without manual pointer management.