W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2013

Re: [whatwg] asynchronous JSON.parse

From: Tobie Langel <tobie.langel@gmail.com>
Date: Fri, 8 Mar 2013 11:15:37 +0100
To: Robin Berjon <robin@w3.org>
Message-ID: <53C3650EAFA843429F5360D462BB2B11@gmail.com>
Cc: whatwg@whatwg.org, David Rajchenbach-Teller <dteller@mozilla.com>
On Friday, March 8, 2013 at 10:44 AM, Robin Berjon wrote:
> On 07/03/2013 23:34 , Tobie Langel wrote:
> > Wouldn't some form of event-based API be more indicated? E.g.:
> > 
> > var parser = JSON.parser();
> > parser.parse(src);
> > parser.onparse = function(e) { doSomething(e.data); };
> 
> 
> I'm not sure how that snippet would be different from a single callback API.
> 
> There could possibly be value in an event-based API if you could set it 
> up with a filter, e.g. JSON.filtered("$.*").then(function (item) {}); 
> which would call you for ever item in the root object. Getting an event 
> for every information item that the parser processes would likely flood 
> you in events.

Agreed, you need something higher-level than just JSON tokens. Which is why this can be very much app-specific, unless most of the use cases are to parse data of a format similar to [Object, Object, Object, ..., Object]. This could be special-cased so as to send each object to the event handler as it's parsed.

--tobie
Received on Friday, 8 March 2013 10:16:07 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 8 March 2013 10:16:08 GMT