This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
Invalid JSON in XML Responses?
Post Reply
Return to board index
Post by
encoded
Hi,
I'm trying to create a little tool using wowhead's great XML info for objects. I take a URL, tack on "&xml", and get a nice response. One element of this XML document in particular, the "jsonEquip" field, claims to be JSON. I'll give an example of the value of one of these elements:
slotbak:6,displayid:55383,reqlevel:80,armor:1293,socket1:8,socketbonus:2932,defrtng:43,parryrtng:47,hitrtng:37,str:74,sta:100,dura:55,sellprice:75418,nsockets:1
As far as I can tell, this is invalid JSON. To my knowledge, keys in a JSON object are specified as being strings. Strings in JSON are surrounded in double quotes. The string above does not have its keys surrounded in double quotes. I personally wouldn't care, except that the default python JSON parser refuses to parse the above example, presumably because the keys are not properly specified as strings. I'd rather not have to hack together some way of double quoting the keys to make my parser happy.
Am I missing something about my parser, or about how JSON works when embedded into XML?
Thanks for such a great resource!
PS- It could also be noted that a JSON object should be wrapped in curly brackets {}. Those are easy enough to add on my side however.
Post by
Incendium
This
library will correctly parse the provided JSON.
ECMAScript 262
(read: JavaScript) standards are much more lenient and do not require quotes around object key names while
RFC4627
does. Most JSON parsers will side with RFC4627's stricter standards.
Post by
239559
This post was from a user who has deleted their account.
Post by
pelf
s/(\w+?):(\d+)/\1:"\2"/
?
Excuse me if the regex isn't exactly right -- I was more making a joke than offering something truly useful :).
Post by
encoded
Yeah, I've been able to get things working... Just a shame that the default JSON parser in python2.6 won't handle the JSON returned by wowhead. But thanks for the clarafication. :)
Thanks for the link to the alternative parser, I'll give it a shot.
Post by
tbeseda
Just a shame that the default JSON parser in python2.6 won't handle the JSON returned by wowhead.
Neither will PHP, decode_json()...
Post by
332041
This post was from a user who has deleted their account.
Post by
Erorus
Just beware of parsing
Footman Tunic
or
Demon Hide Sack
, or really anything with apostrophes or colons in source names.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.