From e52629b36d96f4266b6217214055b1965594ebeb Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:33 +0300 Subject: [PATCH] json: Possible bad transcription of struct to JSON - indentation of member of type structure without given name (fixes #20600) --- vlib/json/tests/json_encode_embed_test.v | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vlib/json/tests/json_encode_embed_test.v b/vlib/json/tests/json_encode_embed_test.v index 085c5815b..a7f12df9b 100644 --- a/vlib/json/tests/json_encode_embed_test.v +++ b/vlib/json/tests/json_encode_embed_test.v @@ -9,6 +9,16 @@ struct Json { test f64 } +struct Article { + title string + description string +} + +struct ArticlePlus { + Article + perex string +} + fn test_main() { str := '{"inner":[1,2,3,4,5],"test":1.2}' data := json.decode(Json, str) or { @@ -25,3 +35,22 @@ fn test_main() { dump(data_json) assert data_json == str } + +fn test_encode_array_of_embedded_structs() { + list_of_object := [ + ArticlePlus{ + title: 'One good title' + description: 'this is the first' + }, + ArticlePlus{ + title: 'Other good title' + description: 'more one' + }, + ArticlePlus{ + title: 'Other good title' + description: 'more one' + perex: 'good perex' + }, + ] + assert json.encode(list_of_object) == '[{"title":"One good title","description":"this is the first","perex":""},{"title":"Other good title","description":"more one","perex":""},{"title":"Other good title","description":"more one","perex":"good perex"}]' +} -- 2.39.5