json
Converts between Lua values and JSON text.
Functions
json.encode
json.encode(value [, opts]) -> string| Name | Type | Description |
|---|---|---|
| value | any | nil, boolean, number, string or table. |
| optsoptional | table | integer | {indent = n} or just n: pretty-print with n spaces, 0 to 8. |
Tables keyed exactly 1 to n become arrays, others objects.
Returns compact JSON unless indent is set
- Functions, userdata, NaN and infinity become null; boolean and table keys are skipped.
- Raises past 64 nesting levels, which self-referencing tables hit.
json.decode
json.decode(text) -> any| Name | Type |
|---|---|
| text | string |
Parses JSON; numbers without '.', 'e' or 'E' become integers.
Returns value; null becomes nil
- Raises on malformed input, so pcall untrusted text.
- null leaves holes in arrays, which throws off #.