[web-devel] when we switch to aeson, perhaps a QQ for JSON..

Max Cantor mxcantor at gmail.com
Thu Mar 17 15:33:41 CET 2011


I think my main issue is that it because it needs a map from json <-> haskell type, can you have json objects with differing keys?

For instance, say we want to return one of:
{status: 0, content: "boo.."} and {status: 1, errorMsg: "duck typing is bullsh*t"}

with the json library's generic functions you can't do this.  even:

data Msg = Msg { status :: Int, content :: Maybe String, errorMsg :: Maybe String } 

won't work as it will choke on the "missing" fields.

Max

On Mar 17, 2011, at 10:01 PM, Greg Weber wrote:

> 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.
> 
> documentToJson :: [Field] -> J.Value
> documentToJson = jsonMap . map toAssoc
> 
> toAssoc :: Field -> (String, J.Value)
> toAssoc (l := v) = (unpack l, toJson v)
> 
> 
> 
> 
> On Wed, Mar 16, 2011 at 11:44 PM, Max Cantor <mxcantor at gmail.com> wrote:
> 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.
> 
> max
> On Mar 17, 2011, at 1:37 PM, Greg Weber wrote:
> 
> > 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.
> >
> > http://hackage.haskell.org/packages/archive/json-enumerator/0.0.1/doc/html/Text-JSON-ToJson.html
> >
> > On Wed, Mar 16, 2011 at 8:32 PM, Max Cantor <mxcantor at gmail.com> wrote:
> > I know that the kickass yesod team is looking to change the json library to aeson.
> >
> > One nice feature would be quasi-quoting for the library like in the following library.
> > hackage.haskell.org/packages/archive/text-json-qq/0.2.0/doc/html/Text-JSON-QQ.html
> > _______________________________________________
> > web-devel mailing list
> > web-devel at haskell.org
> > http://www.haskell.org/mailman/listinfo/web-devel
> >
> 
> 




More information about the web-devel mailing list