title: Javascript json_encode > JSON.parse() array
body: <p>I the following PHP code:</p>
  
  <pre><code>echo "&lt;img src='../images/edit.png' onclick='showEditDiv(" . json_encode($row) . ");'&gt;";
  </code></pre>
  
  <p>Here is the HTML result:</p>
  
  <pre><code>&lt;img src='../images/edit.png' onclick='showEditDiv({"ID":"2","NAME":"John Smith","EMAIL":"johnsmith@domain.com"});'&gt;
  </code></pre>
  
  <p>And here is the Javascript code:</p>
  
  <pre><code>function showEditDiv(data) {
    alert(data);
    data = JSON.parse(data);
    alert(data);
    for (i=0; i&lt; data.length; i++){ 
      alert(data[i]);
    };
  }
  </code></pre>
  
  <p>The problem is I'm not getting the desired array in the JS parameter.
  The first alert shows "[object Object]" and that's all, no more alerts.
  Where is the problem? My code is based on the examples I found here. All I want is to pass an array to JS function, which is in a separated .js file. I don't want to use JQuery, prefer native JS.</p>