This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Hi, I have been trying to parse the JSON output from validator, and 3 parsers, on two platforms are failing (asp.net 2.0, and php (5.2.9) builtin json_decode function). Making the modifications below, the parsers succeed. I think there are 2 separate issues with commas (based on http://www.json.org/): 1) The last element of an array (ie "explanation": "blah") should not have a comment after it. 2) Individual "messages" should have a comma between them i.e. "messages": [ { "name":"param", "name2":"param2" } , { "name":"param", "name2":"param2" } ] <--- SNIP - Current output from validator based on URL (above) fails ---> { "url": "http://www.gb.co.uk/gbgroup/gb-news", "messages": [ { "type": "error", "lastLine": "317", "lastColumn": 24, "message": "end tag for element \"embed\" which is not open", "messageid": 79, "explanation": " explanation blah blah blah", } { "type": "error", "lastLine": "317", "lastColumn": 44, "message": "Attribute \"pluginspage\" is not a valid attribute", "messageid": 108, "explanation": " explanation blah blah blah ", } ], "source": { "encoding": "uft-8" } } <--- /SNIP ---> <--- SNIP - Removing explanation comma and adding comma between messages does parse ---> { "url": "http://www.gb.co.uk/gbgroup/gb-news", "messages": [ { "type": "error", "lastLine": "317", "lastColumn": 24, "message": "end tag for element \"embed\" which is not open", "messageid": 79, "explanation": " explanation blah blah blah" } , { "type": "error", "lastLine": "317", "lastColumn": 44, "message": "Attribute \"pluginspage\" is not a valid attribute", "messageid": 108, "explanation": " explanation blah blah blah " } ], "source": { "encoding": "uft-8" } } <--- /SNIP ---> php 5.2.9 code to Parse: <?php //code fails: $jsonStr = file_get_contents('http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co.uk%2Fgbgroup%2Fgb-news&output=json'); echo $jsonStr; //outputs file $jsonObj = json_decode($jsonStr); print_r($jsonObj); //No Output //code works when no messages output: $jsonStr = file_get_contents('http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co.uk%2F&output=json'); $jsonObj = json_decode($jsonStr); print_r($jsonObj); //Displays object - this page has no messages assocaited /* file check was output from 1st invalid page, saved and then modified * to not have commas after the explanation field, and does have commas * between the messages:[ { ... } , { ... } ] blocks */ $jsonStr = file_get_contents('check'); echo $jsonStr; //outputs file $jsonObj = json_decode($jsonStr); print_r($jsonObj); //No Output ?> So, have i found or bug, or do i need less caffine and more sleep? Thanks, Paul
You're quite right. In addition to those two problems, JSON escaping the "msg" and "explanation" values was not correct. All these are now fixed in CVS and should be available for testing at http://qa-dev.w3.org/wmvs/HEAD/ shortly.
Many errors were fixed, but unfortunately some remain (invalid lastColumn numbers in some XML parsing errors) that are apparently due to old(ish) XML::LibXML on validator.w3.org production boxes. Workaround is in CVS waiting for the next release.
(In reply to comment #2) > Many errors were fixed, but unfortunately some remain (invalid lastColumn > numbers in some XML parsing errors) that are apparently due to old(ish) > XML::LibXML on validator.w3.org production boxes. Workaround is in CVS waiting > for the next release. Newer libxml installed and sample json output passes http://www.jsonlint.com/ I also upgraded validator check with Ville's latest version.
Thanks, closing.