json package:postgresql-simple

Return the JSON ByteString directly
Parse a field to a JSON Value and convert that into a Haskell value using the FromJSON instance. This can be used as the default implementation for the fromField method for Haskell types that have a JSON representation in PostgreSQL. The Typeable constraint is required to show more informative error messages when parsing fails. Note that fromJSONField :: FieldParser (Maybe Foo) will return Nothing on the json null value, and return an exception on SQL null value. Alternatively, one could write optionalField fromJSONField that will return Nothing on SQL null, and otherwise will call fromJSONField :: FieldParser Foo and then return Just the result value, or return its exception. If one would like to return Nothing on both the SQL null and json null values, one way to do it would be to write \f mv -> join <$> optionalField fromJSONField f mv
Convert a Haskell value to JSON using toEncoding. This can be used as the default implementation for the toField method for Haskell types that have a JSON representation in PostgreSQL.