v2 / vlib / json / tests / json_encode_map_test.v
22 lines · 19 sloc · 413 bytes · 8ebbacecd60366ac4ba68aa35f9b0e7a0e56ff61
Raw
1import json
2
3struct Test {
4 optional_string ?string
5 optional_array ?[]string
6 optional_struct_array ?[]string
7 optional_map ?map[string]string
8}
9
10fn test_main() {
11 test := Test{}
12 encoded := json.encode(test)
13 assert dump(encoded) == '{}'
14
15 test2 := Test{
16 optional_map: {
17 'foo': 'bar'
18 }
19 }
20 encoded2 := json.encode(test2)
21 assert dump(encoded2) == '{"optional_map":{"foo":"bar"}}'
22}
23