Thread: [Pyparsing] jsonParser.py patch
Brought to you by:
ptmcg
From: thomas_h <th...@go...> - 2008-04-22 15:35:11
|
Hi all, I've changed the jsonParser.py example from the distro to accommodate top-level arrays (as of RFC4627, http://tools.ietf.org/html/rfc4627). Please find the patch attached. Cheers, Thomas |
From: Paul M. <pt...@au...> - 2008-04-22 16:40:34
|
Your attachment was stripped somewhere along the way. Could you please paste it to a http://pyparsing.pastebin.com/? Thanks, -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of thomas_h Sent: Tuesday, April 22, 2008 10:35 AM To: pyp...@li... Subject: [Pyparsing] jsonParser.py patch Hi all, I've changed the jsonParser.py example from the distro to accommodate top-level arrays (as of RFC4627, http://tools.ietf.org/html/rfc4627). Please find the patch attached. Cheers, Thomas |
From: thomas_h <th...@go...> - 2008-04-22 19:43:26
|
Done. It's at http://pyparsing.pastebin.com/m2c33d08d, if that is of help. Thanks for the hints. Thomas On Tue, Apr 22, 2008 at 6:40 PM, Paul McGuire <pt...@au...> wrote: > Your attachment was stripped somewhere along the way. Could you please > paste it to a http://pyparsing.pastebin.com/? > > Thanks, > -- Paul > > > > -----Original Message----- > From: pyp...@li... > [mailto:pyp...@li...] On Behalf Of thomas_h > Sent: Tuesday, April 22, 2008 10:35 AM > To: pyp...@li... > Subject: [Pyparsing] jsonParser.py patch > > Hi all, > > I've changed the jsonParser.py example from the distro to accommodate > top-level arrays (as of RFC4627, http://tools.ietf.org/html/rfc4627). > Please find the patch attached. > > Cheers, > Thomas > > |
From: Paul M. <pt...@au...> - 2008-04-22 21:13:57
|
Thomas - Hrm, well, I can see that this works, but I'm not sold. A jsonObject really *isn't* a choice between a jsonDict and a jsonArray. It really is a '{' members '}', as per the BNF. I think the real problem is elsewhere. The RFC link you gave was very helpful. It states that the content of the JSON string can be any JSON value, which you tripped over because you encountered a JSON array when we were parsing for a JSON object. The solution is not to change the definition of jsonObject. The solution is that we should have been invoking this: jsonValue.parseString(testdata) not this: jsonObject.parseString(testdata) which was my mistake in the original code. Not thinking, I assumed that JSON object was the all-encompassing type, but JSON value is what we are really being given. jsonValue already encompasses checking for all the different JSON value types - not just object and array, but also number, true, false, etc. Try reverting to the original jsonParser.py, but change this statement instead and see if you get successful parsing. (You may find that the results are nested an extra level deep, you'll have to pick out element [0] of the data returned from parseString.) I'll fix this in the next release (coming soon, I hope)! Cheers, -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of thomas_h Sent: Tuesday, April 22, 2008 2:43 PM To: pyp...@li... Subject: Re: [Pyparsing] jsonParser.py patch Done. It's at http://pyparsing.pastebin.com/m2c33d08d, if that is of help. Thanks for the hints. Thomas On Tue, Apr 22, 2008 at 6:40 PM, Paul McGuire <pt...@au...> wrote: > Your attachment was stripped somewhere along the way. Could you > please paste it to a http://pyparsing.pastebin.com/? > > Thanks, > -- Paul > > > > -----Original Message----- > From: pyp...@li... > [mailto:pyp...@li...] On Behalf Of > thomas_h > Sent: Tuesday, April 22, 2008 10:35 AM > To: pyp...@li... > Subject: [Pyparsing] jsonParser.py patch > > Hi all, > > I've changed the jsonParser.py example from the distro to accommodate > top-level arrays (as of RFC4627, http://tools.ietf.org/html/rfc4627). > Please find the patch attached. > > Cheers, > Thomas > > ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javao ne _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |
From: thomas_h <th...@go...> - 2008-04-22 21:47:09
|
Paul, > Hrm, well, I can see that this works, but I'm not sold. A jsonObject really > *isn't* a choice between a jsonDict and a jsonArray. It really is a '{' > members '}', as per the BNF. I think the real problem is elsewhere. Yes, I wasn't very happy with my naming but I'm not very good at naming anyway and I thought it would do. 'jsonObject' should probably be reserved for what I named 'jsonDict', and what I named 'jsonObject' should be called something else. > The RFC link you gave was very helpful. It states that the content of the > JSON string can be any JSON value, which you tripped over because you > encountered a JSON array when we were parsing for a JSON object. I read this too, but wasn't sure I could trust my understanding. Especially after I ran my current "reference implementation" (demjson) on a file containing just "this is a value", which was dismissed as illegal. The RFC defines (if I get it right) 'JSON-text' as the start symbol and says "A JSON text is a serialized object or array. JSON-text = object / array". That might speak in favor of my approach. I think the BNF (I presume you are referring to the sidebar of json.org) supports your understanding as well since there is no dedicated start symbol. (Actually, I can't find that text again where it says JSON is just a JSON value ...). > > The solution is not to change the definition of jsonObject. The solution is > that we should have been invoking this: > > jsonValue.parseString(testdata) Fair enough. It might be overgenerating, though. > jsonValue already encompasses checking for all the different JSON value > types - not just object and array, but also number, true, false, etc. Try > reverting to the original jsonParser.py, but change this statement instead > and see if you get successful parsing. I'm sure this will work, I'll give it a try. Keep up, Thomas |
From: Paul M. <pt...@au...> - 2008-04-22 23:42:42
|
Yes, I was too quick to read that part of the RFC, I was working just off the content of json.org, which is a bit squishier on the format then the RFC is. If what we will get is JSON-text, then let's just call it jsonText, and define it as: jsonText = jsonObject | jsonArray jsonText.ignore(jsonComment) print jsonText.parseString(testdata) And we should be confident now that jsonText matches the JSON-Text from the RFC. -- Paul -----Original Message----- From: pyp...@li... [mailto:pyp...@li...] On Behalf Of thomas_h Sent: Tuesday, April 22, 2008 4:47 PM To: Paul McGuire Cc: pyp...@li... Subject: Re: [Pyparsing] jsonParser.py patch Paul, > Hrm, well, I can see that this works, but I'm not sold. A jsonObject > really > *isn't* a choice between a jsonDict and a jsonArray. It really is a '{' > members '}', as per the BNF. I think the real problem is elsewhere. Yes, I wasn't very happy with my naming but I'm not very good at naming anyway and I thought it would do. 'jsonObject' should probably be reserved for what I named 'jsonDict', and what I named 'jsonObject' should be called something else. > The RFC link you gave was very helpful. It states that the content > of the JSON string can be any JSON value, which you tripped over > because you encountered a JSON array when we were parsing for a JSON object. I read this too, but wasn't sure I could trust my understanding. Especially after I ran my current "reference implementation" (demjson) on a file containing just "this is a value", which was dismissed as illegal. The RFC defines (if I get it right) 'JSON-text' as the start symbol and says "A JSON text is a serialized object or array. JSON-text = object / array". That might speak in favor of my approach. I think the BNF (I presume you are referring to the sidebar of json.org) supports your understanding as well since there is no dedicated start symbol. (Actually, I can't find that text again where it says JSON is just a JSON value ...). > > The solution is not to change the definition of jsonObject. The > solution is that we should have been invoking this: > > jsonValue.parseString(testdata) Fair enough. It might be overgenerating, though. > jsonValue already encompasses checking for all the different JSON > value types - not just object and array, but also number, true, > false, etc. Try reverting to the original jsonParser.py, but change > this statement instead and see if you get successful parsing. I'm sure this will work, I'll give it a try. Keep up, Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javao ne _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |