[Bug 7000] New: returned JSON output is invalid

http://www.w3.org/Bugs/Public/show_bug.cgi?id=7000

           Summary: returned JSON output is invalid
           Product: Validator
           Version: 0.8.5
          Platform: All
               URL: http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co
                    .uk%2Fgbgroup%2Fgb-news&output=json
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: check
        AssignedTo: dave.null@w3.org
        ReportedBy: paul@muckingfuddled.com
         QAContact: www-validator-cvs@w3.org


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


-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Friday, 5 June 2009 19:29:36 UTC