lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Feb 9, 2010 at 1:00 PM, Steve Watkins
<> wrote:
> Hello,
> I'm relatively new to Lua and am looking for a module or script that can
> encode and decode JSON strings inside a .lua script.
> I've looked on luaforge and have been unable to get those to work in my
> Scrite environment - thjs was using the
> -- JSON4Lua: JSON encoding / decoding support for the Lua language.
> -- json Module.
> -- Author: Craig Mason-Jones
> -- Homepage:
> -- Version: 0.9.20
> I was hoping there was an established solid tested way to encode/decode JSON
> using Lua.
> Any info is much appreciated.
My LuaJSON projects uses LPeg for parsing and the strict mode passes
all tests provided by the JSON validator project from  The
non-strict mode permits some more loose handling of constructs.

null and undefined values are preserved as tag-functions for full
round-trip support, however if you want a more native-friendly
decoding to avoid having to check for these 'null' and 'undefined' tag
values, you can use the
1.1.1 release and the json.decode.simple option-set.

json.decode('null', json.decode.simple)
will both return nil values

json.decode('null') will return a value: json.util.null as a
placeholder to permit re-encoding the 'null's explicitly for

The unit tests use lunit and should be easy to check using 'make check'

The makefile is present purely for simplification of some distribution
processes and is not needed for installation (it's a simple recursive
copy to where you need modules stored).

I'm readily available to answer any questions about it.  Any bugs /
behavior problems found are VERY welcome.

Thomas Harning Jr.