{-# OPTIONS_HADDOCK ignore-exports #-}
module Data.Aeson.Safe (
module Data.SafeJSON
, module Aeson
, decode
, decode'
, eitherDecode
, eitherDecode'
, encode
, encodeFile
, decodeStrict
, decodeStrict'
, eitherDecodeStrict
, eitherDecodeStrict'
, decodeFileStrict
, decodeFileStrict'
, eitherDecodeFileStrict
, eitherDecodeFileStrict'
, encodeStrict
, Parser
, parseEither
, parseMaybe
) where
import Data.Aeson as Aeson hiding (
decode
, decode'
, decodeFileStrict
, decodeFileStrict'
, decodeStrict
, decodeStrict'
, eitherDecode
, eitherDecode'
, eitherDecodeFileStrict
, eitherDecodeFileStrict'
, eitherDecodeStrict
, eitherDecodeStrict'
, encode
, encodeFile
, parseJSON
, toJSON
)
import qualified Data.Aeson as A (
decode
, decode'
, decodeFileStrict
, decodeFileStrict'
, decodeStrict
, decodeStrict'
, eitherDecode
, eitherDecode'
, eitherDecodeFileStrict
, eitherDecodeFileStrict'
, eitherDecodeStrict
, eitherDecodeStrict'
, encode
, encodeFile
)
import Data.Aeson.Types
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.SafeJSON
decode :: SafeJSON a => LBS.ByteString -> Maybe a
decode lbs = A.decode lbs >>= parseMaybe safeFromJSON
decode' :: SafeJSON a => LBS.ByteString -> Maybe a
decode' lbs = A.decode' lbs >>= parseMaybe safeFromJSON
eitherDecode :: SafeJSON a => LBS.ByteString -> Either String a
eitherDecode lbs = A.eitherDecode lbs >>= parseEither safeFromJSON
eitherDecode' :: SafeJSON a => LBS.ByteString -> Either String a
eitherDecode' lbs = A.eitherDecode' lbs >>= parseEither safeFromJSON
encode :: SafeJSON a => a -> LBS.ByteString
encode = A.encode . safeToJSON
decodeStrict :: SafeJSON a => BS.ByteString -> Maybe a
decodeStrict lbs = A.decodeStrict lbs >>= parseMaybe safeFromJSON
decodeStrict' :: SafeJSON a => BS.ByteString -> Maybe a
decodeStrict' lbs = A.decodeStrict' lbs >>= parseMaybe safeFromJSON
eitherDecodeStrict :: SafeJSON a => BS.ByteString -> Either String a
eitherDecodeStrict lbs = A.eitherDecodeStrict lbs >>= parseEither safeFromJSON
eitherDecodeStrict' :: SafeJSON a => BS.ByteString -> Either String a
eitherDecodeStrict' lbs = A.eitherDecodeStrict' lbs >>= parseEither safeFromJSON
encodeStrict :: SafeJSON a => a -> BS.ByteString
encodeStrict = LBS.toStrict . encode
decodeFileStrict :: SafeJSON a => FilePath -> IO (Maybe a)
decodeFileStrict fp = do
mVal <- A.decodeFileStrict fp
return $ mVal >>= parseMaybe safeFromJSON
decodeFileStrict' :: SafeJSON a => FilePath -> IO (Maybe a)
decodeFileStrict' fp = do
mVal <- A.decodeFileStrict' fp
return $ mVal >>= parseMaybe safeFromJSON
eitherDecodeFileStrict :: SafeJSON a => FilePath -> IO (Either String a)
eitherDecodeFileStrict fp = do
eVal <- A.eitherDecodeFileStrict fp
return $ eVal >>= parseEither safeFromJSON
eitherDecodeFileStrict' :: SafeJSON a => FilePath -> IO (Either String a)
eitherDecodeFileStrict' fp = do
eVal <- A.eitherDecodeFileStrict' fp
return $ eVal >>= parseEither safeFromJSON
encodeFile :: SafeJSON a => FilePath -> a -> IO ()
encodeFile fp = A.encodeFile fp . safeToJSON