Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created November 2, 2011 23:14
Show Gist options
  • Save seanhess/1335261 to your computer and use it in GitHub Desktop.
Save seanhess/1335261 to your computer and use it in GitHub Desktop.
BSON to JSON
{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}
-- cabal install json
-- cabal install mongoDB
import Text.JSON
import Text.JSON.Generic
import Database.MongoDB
import Data.Bson
-- this doesn't help
instance JSON (Field) where
showJSON doc = JSNull
readJSON (JSObject obj) = Error "woot"
main = do
-- note that overloaded strings makes JSON not able to handle my literal strings for some reason
-- putStrLn $ encode $ toJSON "hello"
putStrLn $ encode $ toJSON ["hello" =: "world"]
{-
/Users/seanhess/sandbox/Haskell/web/bsonToJson.hs:22:25:
No instance for (Data Field)
arising from a use of `toJSON'
Possible fix: add an instance declaration for (Data Field)
In the second argument of `($)', namely
`toJSON ["hello" =: "world"]'
In the second argument of `($)', namely
`encode $ toJSON ["hello" =: "world"]'
In the expression: putStrLn $ encode $ toJSON ["hello" =: "world"]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment