lua-cjson is a C-backed JSON encoder and decoder for Lua. The simplest installation method is LuaRocks:
1 | luarocks install lua-cjson |
Use the LuaRocks command associated with the Lua version used by your application. If compilation fails, install a C compiler and the matching Lua development headers first.
Verify the module:
1 | local cjson = require("cjson") |
For a manual source build, download the project from its official repository, inspect its build settings, then install into a directory listed by package.cpath. Avoid copying a binary module compiled for another Lua ABI or CPU architecture.
When decoding untrusted JSON, limit payload size and depth at the application boundary. JSON null, sparse arrays, invalid numbers, and numeric precision may require explicit configuration depending on the data contract.