Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Erlang
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README
destructure_json.erl
json.erl

README

This is the built version of the erlang file from (http://www.progski.net/blog/2010/destructuring_json_in_erlang_made_easy.html)

USAGE:
<pre>
1> Obj = mochijson2:decode("{ \"post\": { \"title\": \"Destructuring JSON in Erlang Made Easy\" }}").
{struct,[{<<"post">>,
          {struct,[{<<"title">>,
                    <<"Destructuring JSON in Erlang Made Easy">>}]}}]}

2> json:destructure("Obj.post.title", Obj).
<<"Destructuring JSON in Erlang Made Easy">>

3> Obj2 = mochijson2:decode("{ \"person\": { \"name\": \"ryan\", \"friends\": [ \"Brendan\", \"Smokey\", \"Bams\" ] }}").
{struct,[{<<"person">>,
          {struct,[{<<"name">>,<<"ryan">>},
                   {<<"friends">>,[<<"Brendan">>,<<"Smokey">>,<<"Bams">>]}]}}]}

4> json:destructure("Obj.person.friends[1]", Obj2).
<<"Smokey">>
</pre>
Something went wrong with that request. Please try again.