Home

Awesome

lua-resty-json

Json lib for lua and C. The C interface is depicted by ljson_parser.h; while the Lua interface is implemented by json_decoder.lua. The lua interface is built on top of C implementation, and it's implemented using FFI instead of Lua C-API.

Following is an example of Lua usage:

local ljson_decoder = require 'json_decoder'
local instance = ljson_decoder.create()
local result, err = ljson_decoder.parse(instance, line)

Performance

As of I write this README.md, I compare this work against cjson using few real-world json strings. For string-array intensive jsons, our decoder is normally 30% - 50% ahead of cjson. While for the hash-table intensive input, we are only 10-30% better. In an extreme example where there is a super long string, we see 5X speedup. The performance is measured with luajit 2.1.

So far we pay lots of attention to string handling, and did not get chance to improve following aspects:

Floating Point Number

The way we handle following situations may not be what you expect, but the JSON SPEC does not seem to articulate how to handle these situations right either.

TODO