title: Pull and use JSON data from a URL with JavaScript
body: <p>How can I pull and use JSON data using JavaScript?</p>
  
  <p>For example, this <a href="https://graph.facebook.com/btaylor" rel="nofollow">URL</a> has the following JSON:</p>
  
  <pre><code>{
     "id": "220439",
     "name": "Bret Taylor",
     "first_name": "Bret",
     "last_name": "Taylor",
     "link": "http://www.facebook.com/btaylor",
     "username": "btaylor",
     "gender": "male",
     "locale": "en_US"
  }
  </code></pre>
  
  <p>How can I get this data into JavaScript variables?</p>
  
  <p>I'm not looking to use Facebook API or anything dynamic right now, just getting JSON data from a static URL into JavaScript.</p>
  
  <p>In PHP I could easily do this like:</p>
  
  <pre><code>$contents = file_get_contents($url);
  $jsonObj = json_decode($contents);
  echo "Name: ".$jsonObj-&gt;{'name'};
  </code></pre>