{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}
-- | Parsing JSON object values.
module Text.JSON.JSONParse
(
JSONParse(..)
, parseJSON'
) where
import Data.ByteString
import Text.JSONb
import qualified Text.JSON as J
import Text.JSON.Parsec
-- | Parsing JSON object values.
class JSONParse j p e | j -> p, j -> e where
-- | Parses a value into either an error or a JSON object.
parseJSON ::
String -- ^ Source name.
-> p -- ^ The value to parse.
-> Either e j -- ^ Either error or a JSON object.
instance JSONParse JSON ByteString [Char] where
parseJSON =
const decode
instance JSONParse J.JSValue [Char] ParseError where
parseJSON =
parse p_jvalue
-- | Parse a value with an empty source name.
parseJSON' ::
JSONParse j p e =>
p -- ^ The value to parse.
-> Either e j -- ^ Either error or a JSON object.
parseJSON' =
parseJSON []