about summary refs log tree commit diff
path: root/users/Profpatsch/mailbox-org/AesonQQ.hs
blob: f12afdf51584373750a8fcade180afc6c582c4f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{-# LANGUAGE TemplateHaskellQuotes #-}

module AesonQQ where

import Data.Aeson qualified as Json
import Data.Either qualified as Either
import PossehlAnalyticsPrelude
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
            |]
      }