-
Notifications
You must be signed in to change notification settings - Fork 188
JSON API
IgorTimofeev edited this page Jan 3, 2022
·
8 revisions
This library allows to convert Lua objects to JSON strings and vice versa
Contents |
---|
json.encode |
json.decode |
Attempts to encode given data
to JSON string. If some data
content has unsupported type or if it recursively links to itself, then error will be thrown. Supported data types:
- Table
- String
- Number
- Boolean
- Nil
Example:
json.encode({
testString = "hello world",
testTable = {
testArray = [1, 2, 3]
testNumber = 123,
testBool = true,
testNil = nil
}
})
Result:
> "{
\"testString\": \"hello world\",
\"testTable\": {
\"testArray\": [
1,
2,
3
],
\"testNumber\": 123,
\"testBool\": true,
\"testNil\": null
}
}"
Attempts to interpret given data
string as JSON object and convert it to Lua type
Example:
json.decode("{
\"test\": 123,
\"hello\": \"world\"
}")
Result:
> {
test = 123,
hello = "world"
}