Re: [Pyparsing] jsonParser.py patch
Brought to you by:
ptmcg
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 |