[erlang-questions] fast JSON parser in C

Bob Ippolito bob@REDACTED
Sun Jul 27 01:20:19 CEST 2008


On Sat, Jul 26, 2008 at 10:51 AM, Serge Aleynikov <saleyn@REDACTED> wrote:
> Bob Ippolito wrote:
>>
>> On Fri, Jul 25, 2008 at 6:48 PM, Serge Aleynikov <saleyn@REDACTED> wrote:
>>>
>>> Not sure about others but I do find this "variant of JSON" more
>>> convenient
>>> when it comes to debugging JavaScript in a browser (using Firebug
>>> debugger)
>>> as it is visually more compact and not taking as much of screen real
>>> estate.
>>
>> With firebug you can just look at the objects themselves once they're
>> evaluated.
>
> That is if JSON content coming to a web client is properly formed. During
> the
> development stage when a client fetches some JSON content read from the
> server's
> filesystem (say metadata descriptor of a dynamic grid object) it is not
> guaranteed
> to be properly formed.  This is when inspecting "raw" JSON at the
> client-side's
> debugger comes in handy, and protocol succinctness brings value.

I've never seen this happen except when writing my own JSON library...
but don't do that, there's got to be at least two available for nearly
any language that one would use by now... granted I have written two
for Erlang, one for JavaScript (in MochiKit), and one for Python
(simplejson, which i guess is two if you count the "json" package that
will ship with Python 2.6 and 3.0) over the past 4 years or so.

I find that the quotes are the least of your problems anyway when
trying to read JSON, it's the lack of whitespace.

$ curl -s http://mochiads.com/contest/jul08/feed/json
{"games": [{"play_url": "http://www.mochiads.com/games/after-glow/",
"swf_url": "http://games.mochiads.com/c/g/after-glow/AfterGlowMA.swf",
"description": "Trapped in an ancient alien space pilot training
facility you must use your skills to maneuver your spacecraft out of
each area without getting destroyed. The faster you are the better.",
"thumbnail": "http://cdn.mochiads.com/c/g/after-glow/_thumb_100x100.jpg",
"title": "After Glow"}, …

This feed is actually generous about how it does whitespace by
default, imagine the compact encoding where there are no spaces after
the colons and commas! ... but there are tools you can use for that
too. I wouldn't find this significantly easier to read without the
quotes on the keys:

$ curl -s http://mochiads.com/contest/jul08/feed/json | python -msimplejson
{
    "games": [
        {
            "description": "Trapped in an ancient alien space pilot
training facility you must use your skills to maneuver your spacecraft
out of each area without getting destroyed. The faster you are the
better.",
            "play_url": "http://www.mochiads.com/games/after-glow/",
            "swf_url":
"http://games.mochiads.com/c/g/after-glow/AfterGlowMA.swf",
            "thumbnail":
"http://cdn.mochiads.com/c/g/after-glow/_thumb_100x100.jpg",
            "title": "After Glow"
        }, …


-bob


More information about the erlang-questions mailing list