Merge pull request #52 from d5/jsondoc

add 'to_json' and 'from_json' to builtin documentation
This commit is contained in:
Daniel Kang 2019-01-26 06:43:40 -08:00 committed by GitHub
commit c0bb733c67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.