-
Notifications
You must be signed in to change notification settings - Fork 187
JSON API
IgorTimofeev edited this page Jan 3, 2022
·
8 revisions
This library allows to simplify internet requests, to serialize Lua tables as POST-data, to perform URL-safe encoding, to instantly download or run files on HDD.
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": nil
}
}
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,
hell = "world"
}"