Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


T deserializeJson(T)(scope const(char)[] text);
Test @nogc deserialization
import mir.serde: serdeIgnoreIn, serdeIgnore, serdeScoped;
import mir.bignum.decimal;
import mir.rc.array;
import mir.small_array;
import mir.small_string;

static struct Book
    SmallString!64 title;
    bool wouldRecommend;
    SmallString!128 description; // common `string` and array can be used as well (with GC)
    uint numberOfNovellas;
    Decimal!1 price;
    double weight;

    // nogc small-array tags
    SmallArray!(SmallString!16, 10) smallArrayTags;

    // nogc rc-array tags
    RCArray!(SmallString!16) rcArrayTags;

    // nogc scope array tags
    // when used with `@property` and `@serdeScoped`
    @serdeIgnore bool tagsSet; // control flag for test

    void tags(scope SmallString!16[] tags) @property @safe pure nothrow @nogc
        assert(tags.length == 3);
        assert(tags[0] == "one");
        assert(tags[1] == "two");
        assert(tags[2] == "three");
        tagsSet = true;

auto book = q{{
    "title": "A Hero of Our Time",
    "wouldRecommend": true,
    "description": null,
    "numberOfNovellas": 5,
    "price": 7.99,
    "weight": 6.88,
    "tags": [
    "rcArrayTags": [
        "19th century"
    "smallArrayTags": [

import mir.conv: to;

assert(book.description.length == 0);
assert(book.numberOfNovellas == 5);
assert(!double == 7.99);
assert(book.rcArrayTags.length == 3);
assert(book.rcArrayTags[0] == "russian");
assert(book.rcArrayTags[1] == "novel");
assert(book.rcArrayTags[2] == "19th century");
assert(book.smallArrayTags.length == 3);
assert(book.smallArrayTags[0] == "4");
assert(book.smallArrayTags[1] == "5");
assert(book.smallArrayTags[2] == "6");
assert(book.title == "A Hero of Our Time");
assert(book.weight == 6.88);
SerdeException deserializeValueFromJson(T)(scope const(char)[] text, ref T value);