Loading ...
Sorry, an error occurred while loading the content.

Re: [json] parser assistance

Expand Messages
  • f3l
    ... even tough it sounds like a very interesting project, from which many thing can be made from (like error-checking, and stuff like that), it looks to me,
    Message 1 of 3 , Dec 16, 2005
    • 0 Attachment
      On 12/16/05, MPCM <WickedLogic@...> wrote:
      >
      > I have been using JSON in several web projects via javascript and PHP,
      > it is truly a great format and lets us developers focus on apps. I am
      > trying write a parser for JSON, at least to handle the data formats in
      > basic, specifically visual basic. Doing a json encode routine is
      > fairly straight forward (ignoring the fact that vb data types for
      > named arrays (objects) is less than ideal).
      >
      > I've looked over the code in other languages, and I am looking for
      > some guidance from someone a smarter than me in this. I understand the
      > basics of parsing/tokenizing, and the lack of an included regexp
      > ability in vb6 makes this difficult. My goal is to have a vb6 working
      > parser without external dll/references. including a script engine is
      > also not really an option, again the goal is for a raw vb6 parser.
      >
      > The way I was looking at this was to read it char by char and, as it
      > detected each possible data type/set/nest, strip out the inferred
      > closing chars on the end, and pass that sub string and a current
      > position in the existing object to the same routine, letting it
      > recursively call itself to do the parsing.
      >
      > Every time I have headed down this path, it starts to get somewhat
      > complex, and I keep feeling like I am doing this the `wrong` way, the
      > code just seems like too much of a hack. Any suggests insight, code,
      > or pseudo code covering concepts on dealing with this would be much
      > appreciated.
      >
      > --
      > Matt
      >
      > ------------------------------
      > YAHOO! GROUPS LINKS
      >
      >
      > - Visit your group "json <http://groups.yahoo.com/group/json>" on
      > the web.
      >
      > - To unsubscribe from this group, send an email to:
      > json-unsubscribe@yahoogroups.com<json-unsubscribe@yahoogroups.com?subject=Unsubscribe>
      >
      > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
      > Service <http://docs.yahoo.com/info/terms/>.
      >
      >
      > ------------------------------
      >

      even tough it sounds like a very interesting project, from which many thing
      can be made from (like error-checking, and stuff like that),
      it looks to me, that you are re-inventing the wheel, so the question is,
      is it worth it?, and if so, how long do you think it will take?, how about
      testing?

      anyway, there is a JS thingie written in java, called rhino, maybe you
      should check that up, also, there is venkman, which i think must parse JS at
      some point, and its only 200000 (i think) lines long, also there is a script
      that parses JSON, @ http://www.crockford.com/JSON/json.js , but,
      since you dont like regexps, you will probably have to code tghis:

      var p = /^\s*(([,:{}\[\]])|"(\\.|[^\x00-\x1f"\\])*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)\s*/,

      by hand, all i have to say to you is, GOOD LUCK, and please keep us
      posted about your project development!



      --
      //f3l
      http://www.geocities.com/kyoosho/


      [Non-text portions of this message have been removed]
    • Atif Aziz
      Perhaps it may help to look at the JSON parsing bits (written in C#) that are part of the Jayrock[1] project. I originally started with the C# code from
      Message 2 of 3 , Dec 16, 2005
      • 0 Attachment
        Perhaps it may help to look at the JSON parsing bits (written in C#)
        that are part of the Jayrock[1] project. I originally started with the
        C# code from json.org[2] (which I believe was a straight port of the
        Java version) but then re-factored it so that the output of the parser
        was more of an AST (Abstract Syntax Tree). You want to start by checking
        out two files, namely JsonParser.cs and IParserOutput.cs. The JsonParser
        class contains just the parsing code, but the parser itself does not
        mandate a particular class of output (put another way, a particular
        graph of objects and their types). It leaves that up to the
        IParserOutput implementation that's handed to it. So what JsonParser
        essentially does is that it recognizes the various elements of JSON in
        the string being parsed and then calls back the corresponding properties
        or method(s) of IParserOutput to build/yield the desired representation
        for output. The benefit of this approach is of course that the parsing
        code does not change with your transformation strategy (that is, how you
        decode JSON into an object graph or document).

        So here's what I would suggest. Start by porting the IParserOutput
        interface to Visual Basic, which should be straight forward (hint: you
        can essentially use the Variant data type wherever you see object being
        used). Next, create an implementation of this interface that simply
        outputs debug messages in each call. Finally, port over the JsonParser
        code. This will get most of your headaches out of the way. As a test
        supply the diagnostic IParserOutput implementation to JsonParser and see
        if the right messages get pumped out to the debug window for a give JSON
        string. If all goes well, the real work left will be writing a proper
        IParserOutput implementation that yields the VB data types and I assume
        that's where you want to get and spend most of your brains.

        -- Atif

        [1] http://jayrock/berlios.de/
        [2] http://www.crockford.com/JSON/cs

        -----Original Message-----
        From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
        MPCM
        Sent: Friday, December 16, 2005 3:46 PM
        To: json@yahoogroups.com
        Subject: [json] parser assistance

        I have been using JSON in several web projects via javascript and PHP,
        it is truly a great format and lets us developers focus on apps. I am
        trying write a parser for JSON, at least to handle the data formats in
        basic, specifically visual basic. Doing a json encode routine is
        fairly straight forward (ignoring the fact that vb data types for
        named arrays (objects) is less than ideal).

        I've looked over the code in other languages, and I am looking for
        some guidance from someone a smarter than me in this. I understand the
        basics of parsing/tokenizing, and the lack of an included regexp
        ability in vb6 makes this difficult. My goal is to have a vb6 working
        parser without external dll/references. including a script engine is
        also not really an option, again the goal is for a raw vb6 parser.

        The way I was looking at this was to read it char by char and, as it
        detected each possible data type/set/nest, strip out the inferred
        closing chars on the end, and pass that sub string and a current
        position in the existing object to the same routine, letting it
        recursively call itself to do the parsing.

        Every time I have headed down this path, it starts to get somewhat
        complex, and I keep feeling like I am doing this the `wrong` way, the
        code just seems like too much of a hack. Any suggests insight, code,
        or pseudo code covering concepts on dealing with this would be much
        appreciated.

        --
        Matt




        Yahoo! Groups Links
      Your message has been successfully submitted and would be delivered to recipients shortly.