luajit-plus
Prerequisites
The use must have the root permission.
The machine needs to be able to access the following domains to download packages and GPG keys:
You can check the accessibility of the domains by running the following commands:
curl https://openresty.org/package/pubkey.gpg curl https://pkg2.openresty.com/xray-priv-libs/
Configure the software repository
First we need to configure the repository for the binary installer, follow the command below. (The CLIENT_TOKEN in the command needs to be replaced with a valid Token from the subscription email)
For Ubuntu/Debian/CentOS/Rocky/Red Hat Enterprise Linux/Fedora OS/Alibaba Cloud Linux/Tencent Linux:
curl -o get-xray-priv-lib-repo.sh https://pkg2.openresty.com/scripts/get-xray-priv-lib-repo.sh
sudo bash get-xray-priv-lib-repo.sh -l luajit-plus -t CLIENT_TOKEN
For the Alpine:
curl -o get-xray-priv-lib-repo.sh https://pkg2.openresty.com/scripts/get-xray-priv-lib-repo.sh
sudo sh get-xray-priv-lib-repo.sh -l luajit-plus -t CLIENT_TOKEN
Installing packages
For operating systems using the yum package manager, run the following command to install the private library.
sudo yum install --disablerepo="*" --enablerepo=luajit-plus -y openresty-luajit-plus openresty-luajit-plus-devel
For operating systems using the dnf package manager, execute the following command to install the private libraries.
sudo dnf install --disablerepo="*" --enablerepo=luajit-plus -y openresty-luajit-plus openresty-luajit-plus-devel
For operating systems using the apt package manager, execute the following command to install the private libraries.
sudo apt-get install -y openresty-luajit-plus openresty-luajit-plus-dev
For apline OS, execute the following command to install the private libraries.
sudo apk add openresty-luajit-plus openresty-luajit-plus-dev
CJSON compatibility update
This compatibility update was first introduced in luajit-plus plus-v2.1-20261004. Upgrade to this version or later to use the behavior described below.
Number encoding precision
cjson.encode uses 14 significant digits by default, matching lua-cjson. This is intentional compatibility behavior: values requiring more than 14 significant digits may be rounded, and numbers may be written in scientific notation.
local cjson = require "cjson"
print(cjson.encode_number_precision()) -- 14
print(cjson.encode(1000000000000001)) -- 1e+15
Use encode_number_precision to select a precision from 1 to 16. This does not guarantee lossless round trips for every floating-point value. Represent long integer identifiers as strings when every digit must be preserved. Some older versions may produce different number text by default; when upgrading, check signatures, cache keys, and tests that depend on the exact output text.
Compatible number syntax in decoding and validation
With the default decode_invalid_numbers(true) setting, decode, validate, and decode_file all accept nonstandard number syntax supported by lua-cjson, including [01], [1.], [+1], and [0x10]. Decoding [0x10] returns an array containing the number 16.
local cjson = require "cjson"
print(cjson.validate("[0x10]")) -- true
print(cjson.decode("[0x10]")[1]) -- 16
-- If /data/example.json contains [0x10]:
print(cjson.decode_file("/data/example.json")[1]) -- 16
These forms are not standard JSON, so a true result from validate does not imply strict JSON conformance. Compatibility parsing respects the current instance’s settings, including decode_invalid_numbers, decode_allow_comment, and decode_allow_trailing_comma. For example, setting decode_invalid_numbers(false) makes all three APIs reject [0x10].
For syntax errors or nesting beyond the instance’s decode_max_depth limit, validate returns false, while decode and decode_file raise the same parsing error. With cjson.safe, the latter two return nil, err instead. Standard and compatible numbers obey the same depth limit. Instances created with new() have independent settings. The same rules apply to jit.cjson and jit.cjson.safe.
validate checks the input without constructing decoded values, including inputs with compatible number syntax. decode_file reads the file once and retains its contents for compatibility parsing. Both APIs currently execute in the interpreter, including when called from JIT hot loops.
See the JIT CJSON manual for more API usage details.
Recompile OpenResty
You can compile OpenResty by referring to installation. Note that when executing ./configure with the installation path of luajit-plus after the -with-luajit parameter.
wget https://openresty.org/download/$pkg.tar.gz
tar -xzvf $pkg.tar.gz
cd $pkg
./configure --prefix=/opt/openresty \
--with-luajit=/usr/local/openresty/luajit-plus \
...
make
make install