json_decode returns null on a valid value php
<p>Here is my code:</p>

<pre><code>   echo '&lt;br/&gt;';
   echo 'Json data from DB   '.json_encode($output);
   $data=array();
   $array=json_decode($output,true);
   echo '&lt;br/&gt;';
   echo 'Concerted into an array   '.json_encode($array);
</code></pre>

<p>and here is the output:</p>

<pre><code>Json data from DB  [{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}] 
Concerted into an array null 
</code></pre>

<p>why json_devode returns null? If I try the same like this:</p>

<pre><code>$data = '[{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}]';

// convert to an array
$data = json_decode($data, true);
</code></pre>

<p>then it is printed out normally:</p>

<pre><code>Json data from DB  [{"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","3":"1","key-4":"1"}] 
Concerted into an array  {"0":"1","key-1":"1","1":"1","key-2":"1","2":"1","key-3":"1","4":"1","key-4":"1"}
</code></pre>
