# json.encode(value, pretty?) → string
Lua value to JSON text.
| Parameter | Type | |
|---|---|---|
value | any | |
pretty optional | boolean | indented |
| Returns | |
|---|---|
| string |
print(json.encode({name = "rex", hp = 1024}))
Read and write JSON.
Tables whose keys are exactly 1..n become JSON arrays, other tables objects (number keys become strings). JSON
null becomes nil.
json.encode(value, pretty?) → stringLua value to JSON text.
| Parameter | Type | |
|---|---|---|
value | any | |
pretty optional | boolean | indented |
| Returns | |
|---|---|
| string |
print(json.encode({name = "rex", hp = 1024}))
json.decode(text) → any, string?JSON text to a Lua value.
| Parameter | Type | |
|---|---|---|
text | string | JSON (comments and trailing commas allowed) |
| Returns | |
|---|---|
| any | the value, nil on error |
| string? | error |