This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 7000 - returned JSON output is invalid
Summary: returned JSON output is invalid
Status: RESOLVED FIXED
Alias: None
Product: Validator
Classification: Unclassified
Component: check (show other bugs)
Version: 0.8.5
Hardware: All All
: P2 normal
Target Milestone: 0.8.6
Assignee: Ville Skyttä
QA Contact: qa-dev tracking
URL: http://validator.w3.org/check?uri=htt...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-05 19:29 UTC by Paul Smith
Modified: 2010-03-03 17:18 UTC (History)
1 user (show)

See Also:


Attachments

Description Paul Smith 2009-06-05 19:29:29 UTC
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
Comment 1 Ville Skyttä 2009-06-29 18:38:53 UTC
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.
Comment 2 Ville Skyttä 2010-03-02 19:26:52 UTC
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.
Comment 3 Ted Guild 2010-03-03 04:00:37 UTC
(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.
Comment 4 Ville Skyttä 2010-03-03 17:18:32 UTC
Thanks, closing.