This is an old revision of the document!
kmj-json
The kmj-json package provides a JSON codec.
The runtime provides this library through the luaL_newlib auxiliary library function, so all fields can be assumed to be functions.
decode
The decode field contains a function for decoding a JSON encoded type.
Syntax
decode(input: string): (output: any)
This function takes a single argument, that being the JSON encoded representation of a type, and will return a single value, that being the decoded Lua equivalent value type of the given JSON. If the input cannot be parsed, a Lua nil
will be returned.
encode
The encode field contains a function for encoding a Lua value into a JSON encoded type.
Syntax
encode(input: any): (output: string|nil)
This function takes a single argument, that being the Lua value that is intended to be converted to a JSON encoded string, and a single return value containing the JSON encoded representation of the given input. If the input cannot be understood, nil
will be returned. Of the eight basic Lua types, nil, boolean, number, string and table are supported.