diff --git a/vlib/v/fmt/struct.v b/vlib/v/fmt/struct.v index 030f10b525..c09c45939c 100644 --- a/vlib/v/fmt/struct.v +++ b/vlib/v/fmt/struct.v @@ -169,6 +169,9 @@ fn (mut f Fmt) write_anon_struct_field_decl(field_typ ast.Type, field_anon_decl elem_sym := f.table.sym(sym.info.elem_type) if elem_sym.info is ast.Struct { if elem_sym.info.is_anon { + if field_typ.has_flag(.option) { + f.write('?') + } f.write('[]'.repeat(sym.info.nr_dims)) f.write_anon_struct_field_decl(sym.info.elem_type, field_anon_decl) return true diff --git a/vlib/v/fmt/tests/array_option_anon_struct_keep.vv b/vlib/v/fmt/tests/array_option_anon_struct_keep.vv new file mode 100644 index 0000000000..439ba204aa --- /dev/null +++ b/vlib/v/fmt/tests/array_option_anon_struct_keep.vv @@ -0,0 +1,22 @@ +module main + +import json + +struct Data { +mut: + a_token ?[]string + dfv ?[]struct { + key string + } +} + +fn main() { + j := '{ + "a_token2": ["one", "two"], + "a_email2": { + "email": "email@email.ru" + } + }' + d := json.decode(Data, j)! + println(d) +}