lua-users home
lua-l archive

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

On Thu, Sep 9, 2010 at 11:33 AM, David Kolf <> wrote:
> In my implementation empty tables are encoded as JSON arrays. As far as
> I understood, a JavaScript array is an object with added functionality
> (length and so on) so I thought that accidentally creating an array
> instead of an object shouldn't hurt in JavaScript code while the other
> case could hurt if functionality is missing for an array.

I prefer to look at them as completely different types, because JSON
is supposed to be more or less language-neutral (regardless of where
it came from). In JSON, arrays only contain numeric indices, and
objects have string indices. If you're using JSON as a protocol
between two processes, you don't want to suddenly get an array instead
of an object. If part of the protocol includes an object with users
and their levels (for example), and the receiving end is, say, C++,
the receiver has to know that if there are no users, it will be an
empty array, and account for it.

I prefer explicit control over the encoding process. :)