oh, you are using Maybe- the field needs to be filled in with Nothing<br><br><div class="gmail_quote">On Thu, Mar 17, 2011 at 7:52 AM, Greg Weber <span dir="ltr">&lt;<a href="mailto:greg@gregweber.info">greg@gregweber.info</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">That seems like a fundamental limitation of haskell records- they aren&#39;t meant to have empty fields. I would create 2 different kinds of messages or use an alist or a map. Otherwise you could try to wrap the field in a Maybe.<div>

<div></div><div class="h5"><br>
<br><div class="gmail_quote">On Thu, Mar 17, 2011 at 7:33 AM, Max Cantor <span dir="ltr">&lt;<a href="mailto:mxcantor@gmail.com" target="_blank">mxcantor@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


I think my main issue is that it because it needs a map from json &lt;-&gt; haskell type, can you have json objects with differing keys?<br>
<br>
For instance, say we want to return one of:<br>
{status: 0, content: &quot;boo..&quot;} and {status: 1, errorMsg: &quot;duck typing is bullsh*t&quot;}<br>
<br>
with the json library&#39;s generic functions you can&#39;t do this.  even:<br>
<br>
data Msg = Msg { status :: Int, content :: Maybe String, errorMsg :: Maybe String }<br>
<br>
won&#39;t work as it will choke on the &quot;missing&quot; fields.<br>
<font color="#888888"><br>
Max<br>
</font><div><div></div><div><br>
On Mar 17, 2011, at 10:01 PM, Greg Weber wrote:<br>
<br>
&gt; I agree that ToJson as is now is biased towards arrays. I have some code like the below now. After we switch over we should make sure it is easy to create key-value objects. Perhaps we will need a second ToJson that is biased towards key-value objects instead of arrays.<br>



&gt;<br>
&gt; documentToJson :: [Field] -&gt; J.Value<br>
&gt; documentToJson = jsonMap . map toAssoc<br>
&gt;<br>
&gt; toAssoc :: Field -&gt; (String, J.Value)<br>
&gt; toAssoc (l := v) = (unpack l, toJson v)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Mar 16, 2011 at 11:44 PM, Max Cantor &lt;<a href="mailto:mxcantor@gmail.com" target="_blank">mxcantor@gmail.com</a>&gt; wrote:<br>
&gt; ToJson doesn&#39;t seem to be able to generate JSON objects (key/value maps).  Also, one problem that I&#39;ve had with other generic JSON libs is that they dont give you enough control over the JSON structure.  So, you need to write your client code around a particular JSON structure which can be unwieldy at times.<br>



&gt;<br>
&gt; max<br>
&gt; On Mar 17, 2011, at 1:37 PM, Greg Weber wrote:<br>
&gt;<br>
&gt; &gt; Are you using the ToJson converter? I don&#39;t think QQ offers much advantage over utilities that can automatically convert haskell data structures to JSON. I believe aeson comes with this functionality and also some generics functionality if you define a Data instance.<br>



&gt; &gt;<br>
&gt; &gt; <a href="http://hackage.haskell.org/packages/archive/json-enumerator/0.0.1/doc/html/Text-JSON-ToJson.html" target="_blank">http://hackage.haskell.org/packages/archive/json-enumerator/0.0.1/doc/html/Text-JSON-ToJson.html</a><br>



&gt; &gt;<br>
&gt; &gt; On Wed, Mar 16, 2011 at 8:32 PM, Max Cantor &lt;<a href="mailto:mxcantor@gmail.com" target="_blank">mxcantor@gmail.com</a>&gt; wrote:<br>
&gt; &gt; I know that the kickass yesod team is looking to change the json library to aeson.<br>
&gt; &gt;<br>
&gt; &gt; One nice feature would be quasi-quoting for the library like in the following library.<br>
&gt; &gt; <a href="http://hackage.haskell.org/packages/archive/text-json-qq/0.2.0/doc/html/Text-JSON-QQ.html" target="_blank">hackage.haskell.org/packages/archive/text-json-qq/0.2.0/doc/html/Text-JSON-QQ.html</a><br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; web-devel mailing list<br>
&gt; &gt; <a href="mailto:web-devel@haskell.org" target="_blank">web-devel@haskell.org</a><br>
&gt; &gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>