Reattempt RapidJSON merge.

Ported Ken's lua code to C, fixed some bugs.