v / vlib / json
Raw file | 24 loc (20 sloc) | 385 bytes | Latest commit hash ef5be22f8
1import json
2
3struct Result[T] {
4 ok bool
5 result T
6}
7
8struct User {
9 id int
10 username string
11}
12
13fn func[T]() !T {
14 text := '{"ok": true, "result":{"id":37467243, "username": "ciao"}}'
15 a := json.decode(Result[T], text)!
16 return a.result
17}
18
19fn test_decode_with_generic_struct() {
20 ret := func[User]()!
21 println(ret)
22 assert ret.id == 37467243
23 assert ret.username == 'ciao'
24}