lua-users home
lua-l archive

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

2010/9/8 Brian Maher <>:
> Thanks for posting the comparison wiki page.  I notice the "protection
> against bloated arrays when encoding" section.  Does this mean that
> people desire for this:
>  {[1000] = "harhar"}
> To be encoded as this?
>  {"1000":"harhar"}
> Instead of encoding it as:
>  [null,null,...,"harhar"]
> If this is desired, then I could add support for this in lua-yajl.

>From a user point of view, that would seem weird to change the key
type. Another way to handler the situation is to have a non-nil null
value, and to only accept tables with non-sparse array part or
otherwise trigger an error. That way the user has to make an explicit
decision : either use "1000" to get a dictionary, or fill keys 1 to
999 with json.null to get an array.

> Some other interesting things to compare is how the various
> implementations deal with null since mapping a JSON null to Lua nil
> has the side-effect of making it so that there is no way to express a
> JSON "object" that has a null value, and there is no way to express a
> JSON array with nulls on the end:
>  {"foo": null}
>  ["foo", null]

Another similar comparison point is how each implementation let users
declare empty arrays vs. empty dictionaries. I think that when
features overlap between implementations, a little consistency would
help users decide which one is the best for their situation.