-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|515|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Showcase Home -> Functions Libraries


 
Cower
Created : 23 April 2010
 
System : Cross Platform
Language : Blitz Max

JONK

Event-driven JSON parser module for BlitzMax

Repository
JONK is my personal project of boredom back when I was looking for a JSON parser for BlitzMax and couldn't find one that was simple enough to use (in retrospect, JONK may currently be more complex than most, since it's incomplete in some respects [the helper code isn't even in yet, since it's not working]), so I wrote my own, as that is what I tend to do.

The end result is that I have a JSON parser that can parse something like 4mb of JSON very, very quickly. I don't remember the benchmark, but it was fast enough that I was happy. And if it can handle a payload like 4mb, I think it should do just fine with 20kb or less (I don't use it for web stuff, mainly configuration, serialization, etc.).

I think the key thing to notice about JONK is that it's event-driven. The parser does not give you a single shred of information that you can use when it's done parsing. That would be slow and probably just waste memory that never needed to be allocated in the first place. Instead, you pass it an event handler and it'll pass off what it reads the moment it has read something to the event handler, and the event handler decides what to do with it, if anything.

The event handler could produce a TMap of everything read in, it might only hunt for selective bits of the JSON being parsed and ignore everything else (which would be good if you were reading a lot of 2mb files, since that would reduce how much memory needed to be allocated for files). But whatever the event handler does, that's your job to implement it (until I write a helper event handler that does produce a gigantic document with everything that was read, since people apparently like that sort of thing). I figure there's no way I can write an event handler that will do what you need, so it's just better if you write exactly what you need and nothing more, instead of having to work around the code I cram into an event handler.

There are probably bugs, there's not a lot of documentation (if any; again, it's incomplete). In fact, I think there's a bug with the way it reads arrays. If you end up using it for some reason, do me a favor and take a crack at fixing something (even if I expect nobody will ever do such a thing).

In lieu of anything else to say, I'll just let this get ignored for the rest of its time on here.

 

Comments


Friday, 30 March 2018, 09:18
spinal
requires cower.Charset
Friday, 30 March 2018, 10:22
Cower
github.com/nilium/cower.charset

That would also be on github. I don’t know anything about the code anymore so don’t ask me how to use it.
Friday, 30 March 2018, 11:43
spinal
No worries, I'll probably muddle through ☺️