asArray

Attribute for representing a struct/class as an array instead of an object.

Usually structs and class objects are serialized as dictionaries mapping from field name to value. Using this attribute, they will be serialized as a flat array instead. Note that changing the layout will make any already serialized data mismatch when this attribute is used.

@property
asArray
()
()

Examples

struct Fields {
	int f1;
	string f2;
	double f3;
}

struct Test {
	// serialized as name:value pairs ["f1": int, "f2": string, "f3": double]
	Fields object;
	// serialized as a sequential list of values [int, string, double]
	@asArray Fields array;
}

import vibe.data.json;
static assert(is(typeof(serializeToJson(Test()))));

Meta