fromJSON

Deserializes the provided JSON into a struct of type RecordType

public
RecordType
fromJSON
(
RecordType
)
(
JSONValue jsonIn
)

Parameters

jsonIn JSONValue

the JSON to deserialize

Return Value

Type: RecordType

an instance of RecordType

Throws

RemoteFieldMissing = if the field names in the provided RecordType cannot be found within the prpvided JSONValue jsonIn.

Examples

Example deserialization of JSON to our Person struct

	enum EnumType
	{
		DOG,
		CAT
	}

	struct Person
	{
		public string firstname, lastname;
		public int age;
		public bool isMale;
		public JSONValue obj;
		public int[] list;
		public bool[] list2;
		public float[] list3;
		public double[] list4;
		public string[] list5;
		public EnumType animal;
	}

	JSONValue json = parseJSON(`{
"firstname" : "Tristan",
"lastname": "Kildaire",
"age": 23,
"obj" : {"bruh":1},
"isMale": true,
"list": [1,2,3],
"list2": [true, false],
"list3": [1.5, 1.4],
"list4": [1.5, 1.4],
"list5": ["baba", "booey"],
"animal": "CAT"
}
`);

	Person person = fromJSON!(Person)(json);

	debug(dbg)
	{
		writeln("Deserialized as: ", person);	
	}

	assert(cmp(person.firstname, "Tristan") == 0);
	assert(cmp(person.lastname, "Kildaire") == 0);
	assert(person.age == 23);
	assert(person.isMale == true);
	assert(person.obj["bruh"].integer() == 1);
	assert(person.list == [1,2,3]);
	assert(person.list2 == [true, false]);
	assert(person.list3 == [1.5F, 1.4F]);
	assert(person.list4 == [1.5, 1.4]);
	assert(person.list5 == ["baba", "booey"]);
	assert(person.animal == EnumType.CAT);

Meta