v / vlib / json / tests / json_alias_test.v
26 lines · 19 sloc · 438 bytes · 8ebbacecd60366ac4ba68aa35f9b0e7a0e56ff61
Raw
1import json
2
3pub struct User {
4 name string
5 age int
6 height f64
7}
8
9type Users = map[string]User
10
11const json_users = '{
12 "tom": { "name": "Tom", "age": 45, "height": 1.97 },
13 "martin": { "name": "Martin", "age": 40, "height": 1.8 }
14}'
15
16fn test_alias_with_map() {
17 a := json.decode(map[string]User, json_users)!
18 b := json.decode(Users, json_users)!
19
20 assert Users(a) == b
21
22 c := json.encode(a)
23 d := json.encode(b)
24
25 assert c == d
26}
27