{-# LANGUAGE TemplateHaskell #-} module Data.Aeson.THReader where import Data.Aeson import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax.Compat import TH.RelativePaths readJSONFromFile :: (FromJSON a, Lift a) => String -> SpliceQ a readJSONFromFile :: String -> SpliceQ a readJSONFromFile String name = SpliceQ a -> SpliceQ a forall a (m :: * -> *). m (TExp a) -> m (TExp a) liftSplice (SpliceQ a -> SpliceQ a) -> SpliceQ a -> SpliceQ a forall a b. (a -> b) -> a -> b $ do ByteString contents <- String -> Q ByteString qReadFileLBS String name case (ByteString -> Either String a forall a. FromJSON a => ByteString -> Either String a eitherDecode ByteString contents) of Left String err -> String -> SpliceQ a forall (m :: * -> *) a. MonadFail m => String -> m a fail String err Right a res -> SpliceQ a -> SpliceQ a forall (m :: * -> *) a. Splice m a -> Splice m a examineSplice [||res||]