User Tools

Site Tools


Lua CJSON

The Lua CJSON module provides JSON support for Lua.

Features

  • Fast, standards compliant encoding/parsing routines
  • Full support for JSON with UTF-8, including decoding surrogate pairs
  • Optional run-time support for common exceptions to the JSON specification (infinity, NaN,..)

WebHMI supports this module starting from version WebHMI 3.4.

Documentation for CJSON module is available at official site.

There are 2 most important functions: cjson.encode and cjson.decode.

cjson.encode will serialise a Lua value into a string containing the JSON representation.

Example:

value = { true, { foo = "bar" } }
json_text = cjson.encode(value)
-- Returns: '[true,{"foo":"bar"}]'

cjson.decode will deserialise any UTF-8 JSON string into a Lua value or table.

Example:

json_text = '[ true, { "foo": "bar" } ]'
value = cjson.decode(json_text)
-- Returns: { true, { foo = "bar" } }

Page Tools