serializeToJson

Serializes the given value to JSON.

The following types of values are supported:

Json
Used as-is
null
Converted to Json.Type.Null
bool
Converted to Json.Type.Bool
float, double
Converted to Json.Type.Double
short, ushort, int, uint, long, ulong
Converted to Json.Type.Int
string
Converted to Json.Type.String
T[]
Converted to Json.Type.Array
Tstring
Converted to Json.Type.Object
struct
Converted to Json.Type.Object
class
Converted to Json.Type.Object or Json.Type.Null

All entries of an array or an associative array, as well as all R/W properties and all public fields of a struct/class are recursively serialized using the same rules.

Fields ending with an underscore will have the last underscore stripped in the serialized output. This makes it possible to use fields with D keywords as their name by simply appending an underscore.

The following methods can be used to customize the serialization of structs/classes:

Json toJson() const;
static T fromJson(Json src);

string toString() const;
static T fromString(string src);

The methods will have to be defined in pairs. The first pair that is implemented by the type will be used for serialization (i.e. toJson overrides toString).

  1. Json serializeToJson(T value)
  2. void serializeToJson(R destination, T value)
    void
    serializeToJson
    (
    R
    T
    )
    if (
    isOutputRange!(R, char) ||
    isOutputRange!(R, ubyte)
    )
  3. string serializeToJsonString(T value)

Meta