From 914c1a527d41357b0fe6b7d20f4149dcc531b327 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 26 Sep 2020 12:34:26 +0300 Subject: [PATCH] doc: add `json.decode([]Foo, sfoos)? example --- doc/docs.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 6e4a6e0daa..7351a72cf1 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1955,6 +1955,9 @@ fn caller() { ```v import json +struct Foo { + x int +} struct User { name string age int @@ -1974,6 +1977,12 @@ user := json.decode(User, data) or { println(user.name) println(user.last_name) println(user.age) + +// You can also decode JSON arrays: +sfoos := '[{"x":123},{"x":456}]' +foos := json.decode([]Foo, sfoos)? +println(foos[0].x) +println(foos[1].x) ``` Because of the ubiquitous nature of JSON, support for it is built directly into V.