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