<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Handling JSON Objects in CouchDB Native Erlang Views</title>
	<atom:link href="http://jamietalbot.com/2010/03/18/handling-json-objects-in-couchdb-native-erlang-views/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamietalbot.com/2010/03/18/handling-json-objects-in-couchdb-native-erlang-views/</link>
	<description>Adventures in Engrish</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:44:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Rosswart</title>
		<link>http://jamietalbot.com/2010/03/18/handling-json-objects-in-couchdb-native-erlang-views/comment-page-1/#comment-133</link>
		<dc:creator>Rosswart</dc:creator>
		<pubDate>Thu, 30 Sep 2010 21:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://jamietalbot.com/?p=63#comment-133</guid>
		<description>You can place the unwrapping in the helper function
to further reduce the code:

Get = fun(K, {P}) -&gt; proplists:get_value(K, P) end</description>
		<content:encoded><![CDATA[<p>You can place the unwrapping in the helper function<br />
to further reduce the code:</p>
<p>Get = fun(K, {P}) -> proplists:get_value(K, P) end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rosswart</title>
		<link>http://jamietalbot.com/2010/03/18/handling-json-objects-in-couchdb-native-erlang-views/comment-page-1/#comment-132</link>
		<dc:creator>Rosswart</dc:creator>
		<pubDate>Thu, 30 Sep 2010 20:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://jamietalbot.com/?p=63#comment-132</guid>
		<description>Thank you for that post. It helped me to figure out how to emit JSON objects from my Erlang view.

It seems that CouchDB wraps property lists in a tuple to flag them as JSON objects:
{Proplist} = {[{&lt;&lt;&quot;this&quot;&gt;&gt;, &quot;prop&quot;}, {&lt;&lt;&quot;list&quot;&gt;&gt;, &quot;is a JSON object}]}

So you can use proplists:get_value/2 also deep down in your JSON document.
In my example I use Get to make the code more readable.

fun({Doc}) -&gt;
		Get = fun(K, L) -&gt; proplists:get_value(K, L) end,
		case Get(&lt;&lt;&quot;type&quot;&gt;&gt;, Doc) of
			&lt;&lt;&quot;usage&quot;&gt;&gt; -&gt;
				[Year, Month, Day, Hour, Minute &#124; _] = Get(&lt;&lt;&quot;timestamp&quot;&gt;&gt;, Doc),
				lists:foreach(
				  fun({Row}) -&gt;
						  TrackingID = Get(&lt;&lt;&quot;t&quot;&gt;&gt;, Row),
						  In = Get(&lt;&lt;&quot;i&quot;&gt;&gt;, Row),
						  Out = Get(&lt;&lt;&quot;o&quot;&gt;&gt;, Row),
						  Emit([TrackingID, Year, Month, Day, Hour, Minute],[In, Out])
				  end,
				  Get(&lt;&lt;&quot;data&quot;&gt;&gt;, Doc));
			_ -&gt;
				ok
		end
end.

If you want to emit JSON objects from an Erlang view just do for example

Emit(&lt;&lt;&quot;Example&quot;&gt;&gt;, {[{&lt;&lt;&quot;prop&quot;&gt;&gt;, &quot;list example&quot;}]})

Rosswart</description>
		<content:encoded><![CDATA[<p>Thank you for that post. It helped me to figure out how to emit JSON objects from my Erlang view.</p>
<p>It seems that CouchDB wraps property lists in a tuple to flag them as JSON objects:<br />
{Proplist} = {[{< <"this">>, "prop"}, {< <"list">>, "is a JSON object}]}</p>
<p>So you can use proplists:get_value/2 also deep down in your JSON document.<br />
In my example I use Get to make the code more readable.</p>
<p>fun({Doc}) -><br />
		Get = fun(K, L) -> proplists:get_value(K, L) end,<br />
		case Get(< <"type">>, Doc) of<br />
			< <"usage">> -><br />
				[Year, Month, Day, Hour, Minute | _] = Get(< <"timestamp">>, Doc),<br />
				lists:foreach(<br />
				  fun({Row}) -><br />
						  TrackingID = Get(< <"t">>, Row),<br />
						  In = Get(< <"i">>, Row),<br />
						  Out = Get(< <"o">>, Row),<br />
						  Emit([TrackingID, Year, Month, Day, Hour, Minute],[In, Out])<br />
				  end,<br />
				  Get(< <"data">>, Doc));<br />
			_ -><br />
				ok<br />
		end<br />
end.</p>
<p>If you want to emit JSON objects from an Erlang view just do for example</p>
<p>Emit(< <"Example">>, {[{< <"prop">>, "list example"}]})</p>
<p>Rosswart</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogdan</title>
		<link>http://jamietalbot.com/2010/03/18/handling-json-objects-in-couchdb-native-erlang-views/comment-page-1/#comment-45</link>
		<dc:creator>bogdan</dc:creator>
		<pubDate>Fri, 23 Apr 2010 12:31:09 +0000</pubDate>
		<guid isPermaLink="false">http://jamietalbot.com/?p=63#comment-45</guid>
		<description>That is very indeed insightful. It saved from a lot of trouble.&lt;br&gt;&lt;br&gt;Thank you,</description>
		<content:encoded><![CDATA[<p>That is very indeed insightful. It saved from a lot of trouble.</p>
<p>Thank you,</p>
]]></content:encoded>
	</item>
</channel>
</rss>

