1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/json/json_option_struct_test.v
2023-04-13 08:17:40 +02:00

24 lines
366 B
V

import json
pub struct SomeStruct {
pub mut:
test ?string
}
pub struct MyStruct {
pub mut:
result ?SomeStruct
id string
}
fn test_main() {
a := MyStruct{
id: 'some id'
result: SomeStruct{}
}
encoded_string := json.encode(a)
assert encoded_string == '{"result":{},"id":"some id"}'
test := json.decode(MyStruct, encoded_string)!
assert test == a
}