json

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.

On this page

Functions

# json.encode(value, pretty?) → string

Lua value to JSON text.

ParameterType
valueany
pretty optionalbooleanindented
Returns
string
print(json.encode({name = "rex", hp = 1024}))

# json.decode(text) → any, string?

JSON text to a Lua value.

ParameterType
textstringJSON (comments and trailing commas allowed)
Returns
anythe value, nil on error
string?error