{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE StarIsType #-} {-# LANGUAGE TypeFamilies #-} module Data.Managed.Encodings.JSON where import Data.Aeson (FromJSON, Result(..), ToJSON, Value, fromJSON, toJSON) import Data.Managed.Encoding data JSON instance Encoding JSON where type In JSON = Value type Out JSON = Value instance (ToJSON a) => Encode a JSON where encode :: a -> Out JSON encode = a -> Out JSON forall a. ToJSON a => a -> Value toJSON instance (FromJSON a) => Decode a JSON where decode :: In JSON -> Maybe a decode In JSON v = case Value -> Result (Maybe a) forall a. FromJSON a => Value -> Result a fromJSON Value In JSON v of Error String _ -> Maybe a forall a. Maybe a Nothing Success Maybe a x -> Maybe a x