From c9d6242c6da25a6b07602a92f675ceb76795ec5a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 20 Aug 2021 11:41:09 +0300 Subject: [PATCH] json: top level array test --- vlib/json/json_test.v | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vlib/json/json_test.v b/vlib/json/json_test.v index f10db853bb..ca6b2ac3e7 100644 --- a/vlib/json/json_test.v +++ b/vlib/json/json_test.v @@ -27,6 +27,16 @@ fn test_simple() ? { assert y.title == .worker } +fn test_decode_top_level_array() { + s := '[{"name":"Peter", "age": 29}, {"name":"Bob", "age":31}]' + x := json.decode([]Employee, s) or { panic(err) } + assert x.len == 2 + assert x[0].name == 'Peter' + assert x[0].age == 29 + assert x[1].name == 'Bob' + assert x[1].age == 31 +} + fn bar(payload string) ?Bar { // ?T doesn't work currently result := json.decode(T, payload) ? return result