diff --git a/vlib/json/tests/json_decode_arr_ref_test.v b/vlib/json/tests/json_decode_arr_ref_test.v new file mode 100644 index 00000000000000..7d8b7610fe3bb4 --- /dev/null +++ b/vlib/json/tests/json_decode_arr_ref_test.v @@ -0,0 +1,10 @@ +import json + +struct Test { + a string +} + +fn test_main() { + x := json.decode([]&Test, '[{"a":"a"}]') or { exit(1) } + assert x[0].a == 'a' +} diff --git a/vlib/v/gen/c/json.v b/vlib/v/gen/c/json.v index b0800e6ee7e243..6ca497f5576267 100644 --- a/vlib/v/gen/c/json.v +++ b/vlib/v/gen/c/json.v @@ -1021,7 +1021,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size s = '${styp} val = ${fn_name}((cJSON *)jsval); ' } else if is_array_fixed_val { s = ' - ${result_name}_${styp} val2 = ${fn_name} ((cJSON *)jsval); + ${result_name}_${styp.replace('*', '_ptr')} val2 = ${fn_name} ((cJSON *)jsval); if(val2.is_error) { ${array_free_str} return *(${result_name}_${ret_styp}*)&val2; @@ -1030,7 +1030,7 @@ fn (mut g Gen) decode_array(utyp ast.Type, value_type ast.Type, fixed_array_size memcpy(&val, (${styp}*)val2.data, sizeof(${styp}));' } else { s = ' - ${result_name}_${styp} val2 = ${fn_name} ((cJSON *)jsval); + ${result_name}_${styp.replace('*', '_ptr')} val2 = ${fn_name} ((cJSON *)jsval); if(val2.is_error) { ${array_free_str} return *(${result_name}_${ret_styp}*)&val2;