title: Accessing JSON data with Django
body: <p><strong>Disclaimer:</strong> I'm completely new to parsing and accessing JSON, and I'm only starting to get the ropes of django.</p>
  
  <p><strong>Details:</strong> </p>
  
  <p>I'm trying to access some data inside of a JSON object I obtain in a django template:</p>
  
  <p>example JSON:</p>
  
  <pre><code>{"entry":[
  {"id":"1234567","hash":"1234567",
  ..."name":{"givenName":"John","familyName":"Doel","formatted":"John H. Doe"},
  ..."currentLocation":"Los Angeles, CA",
  ..."emails":[{"primary":"true","value":"jdoe@example.com"}],
  ..."accounts":[
      ...{"domain":"facebook.com","url":"http:\/\/www.facebook.com\/john.doe",..."shortname":"facebook"},
      ...{"domain":"twitter.com","display":"@jdoe411","url":"http:\/\/twitter.com\/jdoe411",..."shortname":"twitter"}],
  ..."urls":[{"value":"http:\/\/www.example.com","title":"example url"},]}
  ]}
  </code></pre>
  
  <p>Obtained with Django Template Tag:</p>
  
  <pre><code>@register.inclusion_tag('includes/gravatar_links.html')
  def gravatar_links(email, first_name):
      url = "http://www.gravatar.com/" + hashlib.md5(email.lower()).hexdigest()
      url += '.json'
  
      response = urllib2.urlopen(url)
      interm = simplejson.load(response)
      data = simplejson.dumps(interm)
      name = first_name
  
  return {'gravatar_links': {'name': name, 'data': data}}
  </code></pre>
  
  <p>which I just call <code>{{ gravatar_links.name }}</code> and <code>{{ gravatar_links.data }}</code>, and I can see the user's name and the JSON data as described.</p>
  
  <p><strong>Goal:</strong></p>
  
  <p>I want to access specific keys in the JSON object, namely <code>"accounts"</code> and <code>"urls"</code>, and customize the output, (e.g.) <code>"Follow {{ gravatar_links.name }} on &lt;a href="{{ gravatar_links.data.accounts.url }}"&gt;{{ gravatar_links.data.accounts.shortname }}&lt;/a&gt; and see their work at &lt;a href="{{ gravatar_links.data.urls.url }}"&gt;{{ gravatar_links.data.urls.title }}&lt;/a&gt;"</code></p>
  
  <p>Which ideally would produce:</p>
  
  <p><code>"Follow John on Twitter and Facebook and see their work at example url"</code></p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><strike>Should I just use django/python to do this, or is this something better handled by jQuery?</strike></li>
  <li>If the <code>"accounts"</code> come as a list, how can I output it as a comma separated list?</li>
  <li>Are there any security issues I should be aware of with this method?</li>
  </ol>