[whatwg] asynchronous JSON.parse
Tobie Langel
tobie.langel at gmail.com
Fri Mar 8 02:15:37 PST 2013
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
More information about the whatwg
mailing list