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.

mir.ion.deser

High level deserialization API

T deserializeJson(T)(scope const(char)[] text);
Examples:
Test @nogc deserialization
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

    @serdeScoped
    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": [
        "one",
        "two",
        "three"
    ],
    "rcArrayTags": [
        "russian",
        "novel",
        "19th century"
    ],
    "smallArrayTags": [
        "4",
        "5",
        "6"
    ]
    }}
    .deserializeJson!Book;

import mir.conv: to;

assert(book.description.length == 0);
assert(book.numberOfNovellas == 5);
assert(book.price.to!double == 7.99);
assert(book.tagsSet);
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);
assert(book.wouldRecommend);
SerdeException deserializeValueFromJson(T)(scope const(char)[] text, ref T value);
template deserializeValue(string[] symbolTable)
Deserialize aggregate value using compile time symbol table
SerdeException deserializeValue(T)(IonDescribedValue data, ref T value)
if (!isFirstOrderSerdeType!T);
Deserialize aggregate value
Parameters:
IonDescribedValue data IonDescribedValue 
T value value to deserialize
Returns:
SerdeException
alias deserializeValue = .deserializeValue_;