Added code for exporting to JSON.
Fixed erroneous json formated string.
Cleaned up code in json.lua.