TonyGen / mongoDB-haskell

MongoDB driver for Haskell
http://hackage.haskell.org/package/mongoDB
Apache License 2.0
57 stars 14 forks source link

Convert BSON to JSON #8

Open seanhess opened 12 years ago

seanhess commented 12 years ago

Hi, I'm new to haskell, so I have no idea whether this kind of code belongs in the BSON repo, the JSON repo, or something else, but I needed a way to serialize BSON to JSON.

https://gist.github.com/1335856

Can you use this? (Note that it's not quite done). If not, where does this kind of mapping between two separate libraries live in haskell-land? BSON and JSON are such close cousins that it seems like it should be easier.

Is there a better way to do this?

Also note that it seems that most of the libraries use Text.Text now instead of CompactString, which made it annoying to convert between the two.

Thanks!

TonyGen commented 12 years ago

Hi Sean, thanks for the code. I will look at it in a few weeks. You could create your own package for this if you wanted. A third package on top of json and bson packages is ok.

gregwebs commented 12 years ago

you could see what happens if you use deriving Generic

https://github.com/bos/aeson/blob/master/examples/Generic.hs

seanhess commented 12 years ago

That is awesome. That's pretty much exactly what I should have done. Thanks On Dec 9, 2011, at 2:13 PM, Greg Weber wrote:

you could see what happens if you use deriving Generic

https://github.com/bos/aeson/blob/master/examples/Generic.hs


Reply to this email directly or view it on GitHub: https://github.com/TonyGen/mongoDB-haskell/issues/8#issuecomment-3086010

TonyGen commented 12 years ago

Hi Sean, so how did you convert BSON to JSON using Generics?

seanhess commented 12 years ago

I didn't. I just assumed that the above example did it. Does it not work?

On Dec 20, 2011, at 4:07 PM, Tony Hannanreply@reply.github.com wrote:

Hi Sean, so how did you convert BSON to JSON using Generics?


Reply to this email directly or view it on GitHub: https://github.com/TonyGen/mongoDB-haskell/issues/8#issuecomment-3226964

tobyhede commented 12 years ago

+1 to that. Attempting to get generics working at the moment

seanhess commented 12 years ago

Did anybody get this working? Example?

gregwebs commented 12 years ago

Someone has done this with persitent-mongoDB. They have an Aeson -> PersistentValue converter. A PersistValue gets converted into BSON in persitent-mongoDB https://github.com/periodic/LoLLogs/blob/master/parser/Data/GameLog/PersistTH.hs

jhickner commented 11 years ago

I've gotten good results by writing a conversion from Data.Bson.Value to Aeson.Value. Once you have an Aeson.Value converting to JSON is as easy as running Aeson.encode.

Code here: https://gist.github.com/4092219