local rapidjson =require('rapidjson')
rapidjson.encode()
rapidjson.decode()
rapidjson.load()
rapidjson.dump()
Usage without luarocks
Use cmake -H. -Bbuild -G<generator-name> go generate project.
If you use a non standard lua install location, add environment variable LUA_DIR to the directory contains include and lib for you lua installtion. eg.
cmake --build build --config Release to build the rapidjosn.so or rapidjosn.dll library.
Then link that library to you project or copy to desired place.
Tips: use cmake --help to see a list of generator-name available.
Value Type Mappings
Lua Type
JSON type
Notes
rapidjson.null
null
true
true
false
false
string
string
table
array
when meta field __jsontype is 'array' or no __jsontype meta filed and table length > 0 or table length == 0 and empty_table_as_array option is specified
table
object
when not an array, all non string keys and its values are ignored.
number
number
Test
Clone or download source code, in the project root folder:
luarocks install luautf8
luarocks install busted
luarocks make
busted
Performance
To compare speed of rapidjson and other json libraries:
lua performance/run.lua
The result on my Macbook Pro shows:
For decoding, lua-rapidjson is slightly faster than lua-cjson in most cases.
For encoding, lua-rapidjson is always faster than lua-cjson, and much faster when encoding numbers.
请发表评论