rsjson
is a Rust library designed to be called from OpenResty Lua for JSON encoding and decoding. It provides a
high-performance, safe, and easy-to-use solution for working with JSON data in Lua.
- High Performance: Written in Rust,
rsjson
is designed for speed. - Safety: Leverages Rust's strong type system and error handling.
- Ease of Use: Simple API with only two methods,
encode
anddecode
.
- Clone the repository and navigate to its directory.
- Run
cargo build --release
. - The dynamic library (
librsjson.so
on Linux,librsjson.dylib
on macOS) will be in thetarget/release
directory.
Copy the rsjson.lua
file to your OpenResty Lua project.
Here's a simple example demonstrating how to use rsjson
:
local json = require('rsjson')
local json_string = '{"user": "demo", "debug": true, "unique_id": 123456, "meta": {"items": ["1","2","3"]}}'
-- Decode JSON string to Lua table
local doc = json.decode(json_string)
print(doc)
-- Encode Lua table to JSON string
print(json.encode(doc))
json.decode(json_string: string) -> table
Decodes a JSON-formatted string and returns a Lua table.
json.encode(lua_table: table) -> string
Encodes a Lua table into a JSON-formatted string.
Feel free to open issues or pull requests if you have suggestions or improvements.
This project is licensed under the MIT License.