User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lua_cjson [2019/01/09 14:29] (current)
akuzmuk created
Line 1: Line 1:
 +====== Lua CJSON ======
 +
 +The [[https://​www.kyne.com.au/​~mark/​software/​lua-cjson-manual.html|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 [[https://​www.kyne.com.au/​~mark/​software/​lua-cjson-manual.html|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:
 +<code lua>
 +value = { true, { foo = "​bar"​ } }
 +json_text = cjson.encode(value)
 +-- Returns: '​[true,​{"​foo":"​bar"​}]'​
 +</​code>​
 +
 +**cjson.decode** will deserialise any UTF-8 JSON string into a Lua value or table.
 +
 +Example:
 +<code lua>
 +json_text = '[ true, { "​foo":​ "​bar"​ } ]'
 +value = cjson.decode(json_text)
 +-- Returns: { true, { foo = "​bar"​ } }
 +</​code>​
 +
 +
  

Page Tools