@@ -552,15 +552,19 @@ instance FromField UUID where
552552
553553-- | json
554554instance FromField JSON.Value where
555− fromField f mbs =
555+ fromField f mbs = parse =<< fromFieldJSONByteString f mbs
556+ where parse bs = case parseOnly (JSON.value' <* endOfInput) bs of
557+ Left err -> returnError ConversionFailed f err
558+ Right val -> pure val
559+
560+-- | Return the JSON ByteString directly
561+fromFieldJSONByteString :: Field -> Maybe ByteString -> Conversion ByteString
562+fromFieldJSONByteString f mbs =
556563 if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
557564 then returnError Incompatible f ""
558565 else case mbs of
559566 Nothing -> returnError UnexpectedNull f ""
560− Just bs ->
561− case parseOnly (JSON.value' <* endOfInput) bs of
562− Left err -> returnError ConversionFailed f err
563− Right val -> pure val
567+ Just bs -> pure bs
564568
565569-- | Parse a field to a JSON 'JSON.Value' and convert that into a
566570-- Haskell value using 'JSON.fromJSON'.