From bbc76a02280c675f194ae9775b62b001e84d7343 Mon Sep 17 00:00:00 2001 From: Daniel Kang Date: Sat, 26 Jan 2019 06:40:13 -0800 Subject: [PATCH] add 'to_json' and 'from_json' to builtin documentation --- docs/builtins.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/builtins.md b/docs/builtins.md index 266249a..e512705 100644 --- a/docs/builtins.md +++ b/docs/builtins.md @@ -63,6 +63,26 @@ v := [1] v = append(v, 2, 3) // v == [1, 2, 3] ``` +## to_json + +Returns the JSON encoding of an object. + +```golang +print(to_json([1, 2, 3])) // [1, 2, 3] +print(to_json(4)) // 4 +print(to_json("five")) // "five" +``` + +## from_json + +Parses the JSON-encoded data and returns an object. + +```golang +arr := from_json(`[1, 2, 3]`) +four := from_json(`4`) +five := from_json(`"five"`) +``` + ## string Tries to convert an object to string object. See [this](https://github.com/d5/tengo/wiki/Variable-Types) for more details on type conversion.