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.<div>
<div><div><br></div></div><div><div>documentToJson :: [Field] -> J.Value</div><div>documentToJson = jsonMap . map toAssoc</div><div><br></div><div><div>toAssoc :: Field -> (String, J.Value)</div><div>toAssoc (l := v) = (unpack l, toJson v)</div>
</div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote">On Wed, Mar 16, 2011 at 11:44 PM, Max Cantor <span dir="ltr"><<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">ToJson doesn't seem to be able to generate JSON objects (key/value maps). Also, one problem that I'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>
<font color="#888888"><br>
max<br>
</font><div><div></div><div class="h5">On Mar 17, 2011, at 1:37 PM, Greg Weber wrote:<br>
<br>
> Are you using the ToJson converter? I don'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>
><br>
> <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>
><br>
> On Wed, Mar 16, 2011 at 8:32 PM, Max Cantor <<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>> wrote:<br>
> I know that the kickass yesod team is looking to change the json library to aeson.<br>
><br>
> One nice feature would be quasi-quoting for the library like in the following library.<br>
> <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>
> _______________________________________________<br>
> web-devel mailing list<br>
> <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>