v2 / vlib / x / json2 / tests / decode_option_field_test.v
21 lines · 19 sloc · 393 bytes · 2d33a7f2819dd5fc1f4aa3b3ca0bcc660810d7af
Raw
1import x.json2
2import time
3
4struct Person {
5mut:
6 name string
7 age ?int = 20
8 birthday time.Time
9 deathday ?time.Time
10}
11
12fn test_main() {
13 resp := '{"name": "Bob", "age": 20, "birthday": "2025-10-12 10:14:52"}'
14 person := json2.decode[Person](resp)!
15 assert '${person}' == "Person{
16 name: 'Bob'
17 age: Option(20)
18 birthday: 2025-10-12 10:14:52
19 deathday: Option(none)
20}"
21}
22