Json Modules

lua-users home
wiki

JSON (JavaScript Object Notation) is a format for serializing data based on the format for JavaScript data structures. For more informations about JSON in general see http://www.json.org/ and [the Wikipedia article on JSON].

A comparison of JSON modules

Since some modules were only called "json" initials were added to create unique names:

This comparison was initially started by DavidKolf, author of dkjson, so it might be biased.

For comparison the default options were used. I (DavidKolf) expect a module to be JSON-compliant with the default settings. An exception was made for Fleece, most of this comparison wouldn't make sense for anything other than the option "E4".

The [feature/compliance tests] and the [speed test] can be found in the repository for dkjson.

Further JSON implementations

JSON implementations that are not included in this comparison (yet):

Major bugs

Escaped characters when encoding

According to [RFC 4627] all characters in the range 0 to 31 plus \\ and \" have to be escaped. However, it is recommended to also escape the Unicode characters U+2028 and U+2029 in order to [generate valid JavaScript as well]. The [original JSON implementation] went even further and escaped most control characters and undefined codepoints in the BMP.

Support for unicode escape sequences \uXXXX when decoding

Other bugs

Edge cases for encoding

JSON cannot represent every Lua structure. This section lists the behavior for some cases. You shouldn't feed any data like this to any JSON module but it's still interesting how the modules handle this. A module must not hang or crash and it should not produce invalid JSON output. (Raising Lua errors is a valid way to deal with such data).

Mixed tables

{[1] = 1, a = 2}

Sparse arrays

{[1000] = "test"}

Handling of NaN and Inf

nan = math.huge * 0

inf = math.huge

Protection against reference cycles when encoding

a = {}

a.a = a

Handling of empty arrays

local json_str = "{'items':[],'properties':{}}"

assert(json_str == json.encode(json.decode(json_str))

Encoding speed

Decoding speed

For the speed tests a table was encoded or decoded 100000 times. The values are not precise and might differ when using other data, but they should give a general orientation.

See Also


RecentChanges · preferences
edit · history
Last edited August 26, 2014 12:43 pm GMT (diff)