xhookLua
Game

json

Converts between Lua values and JSON text.

Functions

json.encode

json.encode(value [, opts]) -> string
NameTypeDescription
valueanynil, boolean, number, string or table.
optsoptionaltable | 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
NameType
textstring

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 #.
json ยท Lua API ยท xhook