<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>7000</bug_id>
          
          <creation_ts>2009-06-05 19:29:29 +0000</creation_ts>
          <short_desc>returned JSON output is invalid</short_desc>
          <delta_ts>2010-03-03 17:18:32 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Validator</product>
          <component>check</component>
          <version>0.8.5</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co.uk%2Fgbgroup%2Fgb-news&amp;output=json</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>0.8.6</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Smith">paul</reporter>
          <assigned_to name="Ville Skyttä">ville.skytta</assigned_to>
          <cc>ted</cc>
          
          <qa_contact name="qa-dev tracking">www-validator-cvs</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>25480</commentid>
    <comment_count>0</comment_count>
    <who name="Paul Smith">paul</who>
    <bug_when>2009-06-05 19:29:29 +0000</bug_when>
    <thetext>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 &quot;explanation&quot;: &quot;blah&quot;) should not have a comment after it.

2) Individual &quot;messages&quot; should have a comma between them i.e.

 &quot;messages&quot;: [ 
{
&quot;name&quot;:&quot;param&quot;, 
&quot;name2&quot;:&quot;param2&quot;
}
, 
{
&quot;name&quot;:&quot;param&quot;, 
&quot;name2&quot;:&quot;param2&quot;
} 
]




&lt;--- SNIP - Current output from validator based on URL (above) fails ---&gt;
{
&quot;url&quot;: &quot;http://www.gb.co.uk/gbgroup/gb-news&quot;,
    &quot;messages&quot;: [
        
          {
              &quot;type&quot;: &quot;error&quot;,
              
              &quot;lastLine&quot;: &quot;317&quot;,
              &quot;lastColumn&quot;: 24,
              &quot;message&quot;: &quot;end tag for element \&quot;embed\&quot; which is not open&quot;,
              &quot;messageid&quot;: 79,
              &quot;explanation&quot;: &quot;  explanation blah blah blah&quot;,
          }
        
          {
              &quot;type&quot;: &quot;error&quot;,
              
              &quot;lastLine&quot;: &quot;317&quot;,
              &quot;lastColumn&quot;: 44,
              &quot;message&quot;: &quot;Attribute \&quot;pluginspage\&quot; is not a valid attribute&quot;,
              &quot;messageid&quot;: 108,
              &quot;explanation&quot;: &quot;   explanation blah blah blah &quot;,
          }
        ],
    &quot;source&quot;: {
        &quot;encoding&quot;: &quot;uft-8&quot;
    }
}
&lt;--- /SNIP ---&gt;


&lt;--- SNIP - Removing explanation comma and adding comma between messages does parse ---&gt;
{
&quot;url&quot;: &quot;http://www.gb.co.uk/gbgroup/gb-news&quot;,
    &quot;messages&quot;: [
        
          {
              &quot;type&quot;: &quot;error&quot;,
              
              &quot;lastLine&quot;: &quot;317&quot;,
              &quot;lastColumn&quot;: 24,
              &quot;message&quot;: &quot;end tag for element \&quot;embed\&quot; which is not open&quot;,
              &quot;messageid&quot;: 79,
              &quot;explanation&quot;: &quot;  explanation blah blah blah&quot;
          }
,        
          {
              &quot;type&quot;: &quot;error&quot;,
              
              &quot;lastLine&quot;: &quot;317&quot;,
              &quot;lastColumn&quot;: 44,
              &quot;message&quot;: &quot;Attribute \&quot;pluginspage\&quot; is not a valid attribute&quot;,
              &quot;messageid&quot;: 108,
              &quot;explanation&quot;: &quot;   explanation blah blah blah &quot;
          }
        ],
    &quot;source&quot;: {
        &quot;encoding&quot;: &quot;uft-8&quot;
    }
}
&lt;--- /SNIP ---&gt;



php 5.2.9 code to Parse:


&lt;?php

//code fails:
$jsonStr = file_get_contents(&apos;http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co.uk%2Fgbgroup%2Fgb-news&amp;output=json&apos;);
echo $jsonStr; //outputs file
$jsonObj = json_decode($jsonStr);
print_r($jsonObj); //No Output

//code works when no messages output:
$jsonStr = file_get_contents(&apos;http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gb.co.uk%2F&amp;output=json&apos;);
$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(&apos;check&apos;); 
echo $jsonStr; //outputs file
$jsonObj = json_decode($jsonStr);
print_r($jsonObj); //No Output
?&gt;



So, have i found or bug, or do i need less caffine and more sleep?


Thanks,

Paul</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25805</commentid>
    <comment_count>1</comment_count>
    <who name="Ville Skyttä">ville.skytta</who>
    <bug_when>2009-06-29 18:38:53 +0000</bug_when>
    <thetext>You&apos;re quite right.  In addition to those two problems, JSON escaping the &quot;msg&quot; and &quot;explanation&quot; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32776</commentid>
    <comment_count>2</comment_count>
    <who name="Ville Skyttä">ville.skytta</who>
    <bug_when>2010-03-02 19:26:52 +0000</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32786</commentid>
    <comment_count>3</comment_count>
    <who name="Ted Guild">ted</who>
    <bug_when>2010-03-03 04:00:37 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; Many errors were fixed, but unfortunately some remain (invalid lastColumn
&gt; numbers in some XML parsing errors) that are apparently due to old(ish)
&gt; XML::LibXML on validator.w3.org production boxes.  Workaround is in CVS waiting
&gt; for the next release.

Newer libxml installed and sample json output passes 

http://www.jsonlint.com/ 

I also upgraded validator check with Ville&apos;s latest version.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>32798</commentid>
    <comment_count>4</comment_count>
    <who name="Ville Skyttä">ville.skytta</who>
    <bug_when>2010-03-03 17:18:32 +0000</bug_when>
    <thetext>Thanks, closing.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>