v / vlib / json
Raw file | 21 loc (16 sloc) | 430 bytes | Latest commit hash 992b50219
1import json
2
3type Test = []bool | []int | []string | string
4
5struct Some {
6 t Test
7}
8
9fn test_json_decode_with_sumtype() {
10 v1 := json.decode(Some, '{"t": ["string", "string2"]}')!
11 println(v1)
12 assert v1.t == Test(['string', 'string2'])
13
14 v2 := json.decode(Some, '{"t": [11, 22]}')!
15 println(v2)
16 assert v2.t == Test([11, 22])
17
18 v3 := json.decode(Some, '{"t": [true, false]}')!
19 println(v3)
20 assert v3.t == Test([true, false])
21}