[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua and JSON
- From: "Thomas Harning Jr." <harningt@...>
- Date: Tue, 9 Feb 2010 13:52:45 -0500
On Tue, Feb 9, 2010 at 1:34 PM, Fabio Mascarenhas <mascarenhas@acm.org> wrote:
> On Tue, Feb 9, 2010 at 4:17 PM, Thomas Harning Jr. <harningt@gmail.com>
> wrote:
>>
>> My LuaJSON projects uses LPeg for parsing and the strict mode passes
>> all tests provided by the JSON validator project from JSON.org The
>> non-strict mode permits some more loose handling of constructs.
>>
>
> +1 for Thomas' module, it works great. Thomas, have you thought about having
> json.encode honor a "__tojson" metamethod (along with a rawencode function),
> so it is easier to extend the encoder to understand app-specific data types?
Hm... that is a good idea. I would probably have it be something of the sort:
__tojson(self, rawencode)
rawencode passed in so that you can take advantage of some of the
infinite recursion avoidance, as well as encoding options. If I get
it right, I'd expect that rawencode would skip the __tojson field of
the immediate object and handle inner objects.
I'll have to work it out further. It would be a 1.2 release when
fully released.
Note that there is a preProcess function that you can pass into the
options that will be passed each individual value for optional
replacement... not the best solution, but a workaround if the feature
is needed immediately (though it will do a 'normal' encoding
afterwards, so no super-special constructs allowed)
--
Thomas Harning Jr.