about summary refs log blame commit diff
path: root/src/Xanthous/Util/JSON.hs
blob: 91d1328e4a10bb9274867729b787db43e41d14e0 (plain) (tree)


















                                                                                
--------------------------------------------------------------------------------
module Xanthous.Util.JSON
  ( ReadShowJSON(..)
  ) where
--------------------------------------------------------------------------------
import Xanthous.Prelude
--------------------------------------------------------------------------------
import Data.Aeson
--------------------------------------------------------------------------------

newtype ReadShowJSON a = ReadShowJSON a
  deriving newtype (Read, Show)

instance Show a => ToJSON (ReadShowJSON a) where
  toJSON = toJSON . show

instance Read a => FromJSON (ReadShowJSON a) where
  parseJSON = withText "readable"
    $ maybe (fail "Could not read") pure . readMay