title: How to pattern match structures returned by mochijson2?
body: <p>I've just started tinkering with Erlang and am building a very simple test web application which is just intended to show my twitter timeline.</p>
  
  <p>I'm using webmachine to write the app and erlyDTL to render the templates.</p>
  
  <p>My question is related to the structures returned by mochiweb's <code>mochijson2:decode/1</code> function.</p>
  
  <p>I can successfully fetch and deocde my timeline as in the following example:</p>
  
  <pre><code>1&gt; Url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=&lt;TWITTER_SCREEN_NAME_HERE&gt;".
  2&gt; inets:start().
  3&gt; {ok, {_, _, Response}} = httpc:request(Url).
  4&gt; DecodedJson = mochijson2:decode(Response).
  </code></pre>
  
  <p>The <code>mochijson2:decode/1</code> function returns a list of tuples of the format:</p>
  
  <pre><code>[{struct, proplist()}, {struct, proplist()}, ...]
  </code></pre>
  
  <p>However, to pass the timeline into erlyDTL I need to get rid of the <code>struct</code> atom tag and simply pass a list of proplists to the webmachine resource (rendered by erlyDTL). Being quite new to pattern matching, I figured that the following list comprehension would achieve this:</p>
  
  <pre><code>Timeline = [Tweet || {struct, Tweet} &lt;- DecodedJson].
  </code></pre>
  
  <p>Indeed, this works perfectly for all of the items in each Tweet proplist except for one, <code>&lt;&lt;"user"&gt;&gt;</code>, the value of which is <em>itself</em> a <code>{struct, proplist()}</code> tuple. I can't for the life of me figure out how to nuke the <code>struct</code> atom from this nested tuple and was wondering if anyone could provide an example of Erlang code which would pattern match both the outer Tweet in <code>{struct, Tweet}</code> and the User <code>{struct, User}</code> contained within each Tweet.</p>
  
  <p>The end goal is to be able to access each tweet in Django template language as in the following example:</p>
  
  <pre><code>{{ tweet.text }}  &lt;- works
  {{ tweet.created_at }}  &lt;- works
  {{ tweet.user.profile_image_url }}  &lt;- ???
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>