vq / vlib / v / gen / c / testdata / json_option_decode_cast.vv
23 lines · 19 sloc · 248 bytes · 1779638616
Raw
1module main
2
3import json
4
5struct Bar {
6 name string
7}
8
9struct Foo {
10 a ?int
11 b ?[]Bar
12}
13
14fn main() {
15 src := '{"a": 1, "b": [{"name": "x"}]}'
16 f := json.decode(Foo, src) or { return }
17 if v := f.a {
18 println(v)
19 }
20 if v := f.b {
21 println(v)
22 }
23}
24