RapidJSON take two

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