about summary refs log blame commit diff
path: root/users/Profpatsch/mailbox-org/AesonQQ.hs
blob: 02e1c2f3dff0f7582b9fa3cb0290431ca379e65f (plain) (tree)






















                                                                                                
{-# LANGUAGE TemplateHaskellQuotes #-}

module AesonQQ where

import Data.Aeson qualified as Json
import Data.Either qualified as Either
import MyPrelude
import PyF qualified
import PyF.Internal.QQ qualified as PyFConf

aesonQQ =
  PyF.mkFormatter
    "aesonQQ"
    PyF.defaultConfig
      { PyFConf.delimiters = Just ('|', '|'),
        PyFConf.postProcess = \exp -> do
          -- TODO: this does not throw an error at compilation time if the json does not parse
          [|
            case Json.eitherDecodeStrict' @Json.Value $ textToBytesUtf8 $ stringToText $(exp) of
              Left err -> error err
              Right a -> a
            |]
      }