Yajl does both parsing and encoding. Clarinet is basically a pure js tool that does much the same thing yajl can do. It's not hard to create JSON.parse and JSON.stringify APIs on top of yajl (though, at that point, you're buffering the final object or need the full json string buffered to parse it)
For node I recommend something like Clarinet and just write the abstraction that's good for your project. If you need to stringify a huge object structure, it's easy to emit json on the fly bit-by-bit as you walk the object graph. Pasring is a little harder, but not too much harder for a simple sax style parser. And Nuno has already done the work for you. For reference, I recently added JSON support to Luvit (Lua doesn't have JSON built-in like V8 JavaScript does). I added JSON.parse and JSON.stringify wrappers on top for people wanting the simpler interface and don't mind a little buffering. https://github.com/luvit/luvit/blob/master/lib/luvit/json.lua Remember, the thing you want to avoid in node is blocking for a long time and buffering everything. I should write a stream object for node (possibly using clarinet as the parser engine). It needs to support back-pressure and per-tick throttling on encoding and writing. Reading from a stream, it's probably fine to parse the chunks as they come in. Usually the CPU is much faster than the incoming stream. On Sun, Feb 12, 2012 at 11:57 AM, Nuno Job <[email protected]> wrote: > Why are people talking about yajl for stringify? Isn't yajl a JSON parser? > >>> Anyway, if you download a 20mb heavy json, and you need to parse and >>> reencode it, yes, you're fucked (maybe) > > Maybe not! That takes less than 0.8 seconds in my browser. Non blocking, > streaming. > Check: github.com/dscape/clarinet > > JSON.parse will probably take 0.2 seconds but it is blocking afaik. > > I wish I could say we had a easier to use wrapper on top of low level > clarinet but I don't think that exists yet. Jann Horn had started a project > called node-jsos (Reads node jesus) that aimed at that. > > Nuno > > Nuno > > On Sun, Feb 12, 2012 at 5:49 PM, Kilian C. <[email protected]> > wrote: >> >> I'm noticing that most of you (also on other similar threads) are focusing >> on parsing objects. >> I'm focusing instead on stringify the output of a big json. >> >> My goal was to avoid blocking the whole process, not to save ram or >> setting up some complicated I/O piping. >> >> I think 99% of the time we need a JSON parse/stringify stream method, we >> are working on a bad design (as me when I opened this thread). >> A fast/small chunk env should be designed top to bottom imho (streamed db >> apis etc). >> >> Anyway, if you download a 20mb heavy json, and you need to parse and >> reencode it, yes, you're fucked (maybe) >> I think a big structure like a 25mb one, is surely iterative (array of >> objects), some parsing/matching hack is applicable then.... >> True difficulties can occur when the structure is recursive, but is a >> marginal case. >> >> On Tue, Apr 19, 2011 at 8:20 PM, Nicholas Campbell >> <[email protected]> wrote: >>> >>> @Mikeal - Right. Thanks for the clarification. >>> >>> @Akzhan - Aye. You can find a repo for yajl-js >>> at https://github.com/polotek/yajl-js >>> >>> - Nick Campbell >>> >>> http://digitaltumbleweed.com >>> >>> >>> On Tue, Apr 19, 2011 at 11:55 AM, Akzhan Abdulin >>> <[email protected]> wrote: >>>> >>>> May be trying to adopt YAJL? >>>> >>>> 2011/4/9 Kilian C. <[email protected]> >>>> >>>>> Hi to all! >>>>> >>>>> is there a non blocking JSON.strongify solution? >>>>> i need to encode a big amount of data... >>>>> >>>>> ty >>>>> >>>>> kilian >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "nodejs" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/nodejs?hl=en. >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "nodejs" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/nodejs?hl=en. >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "nodejs" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/nodejs?hl=en. >> >> >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> You received this message because you are subscribed to the Google >> Groups "nodejs" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en > > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
