1 string json = `1234`; 2 auto deser = decodeJson!(long)(json); 3 assert(deser == 1234); 4 string serialized = encodeJson(deser); 5 assert(serialized == json); 6 7 json = `"hello"`; 8 string deserString = `"hello"`.decodeJson!string; 9 assert(deserString == "hello"); 10 serialized = encodeJson(deserString); 11 assert(json == serialized); 12 13 json = `true`; 14 auto deserBool = json.decodeJson!bool; 15 assert(deserBool == true); 16 serialized = encodeJson(deserBool); 17 assert(serialized == json); 18 19 struct OneField { 20 @JsonProperty("foo") string bar; 21 } 22 json = `{"foo":"hello"}`; 23 auto deserOneField = json.decodeJson!OneField; 24 assert(deserOneField == OneField("hello")); 25 serialized = encodeJson(deserOneField); 26 assert(serialized == json);
Encode an object into a JSON string.