title: jQuery accessing JSON elements
body: <p>I have this JSON string:</p>
  
  <pre><code>{"image":[
      {"img":"_files\/image\/images\/firstimage.jpg","alt":"firstimage alt text"},
      {"img":"secondimage.jpg","alt":"secondimage alt text"}
  ]} 
  </code></pre>
  
  <p>The JSON string is picked from a textarea, then stored in the variable 'content'</p>
  
  <pre><code>var content = $("textarea").val();
  </code></pre>
  
  <p><strong>I am trying to access the elements:</strong></p>
  
  <pre><code>alert(content["image"][0]["img"]);
  </code></pre>
  
  <p><strong>But I get error:</strong> </p>
  
  <blockquote>
    <p>TypeError: content.image is undefined.</p>
  </blockquote>
  
  <p>Eventually I want to manipulate the JSON string by changing and adding elements.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>$.parseJSON did the job:</p>
  
  <pre><code>var content = $.parseJSON($("textarea").val());
  </code></pre>