about summary refs log tree commit diff
path: root/users/Profpatsch/mailbox-org/AesonQQ.hs
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/mailbox-org/AesonQQ.hs')
-rw-r--r--users/Profpatsch/mailbox-org/AesonQQ.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/users/Profpatsch/mailbox-org/AesonQQ.hs b/users/Profpatsch/mailbox-org/AesonQQ.hs
new file mode 100644
index 000000000000..02e1c2f3dff0
--- /dev/null
+++ b/users/Profpatsch/mailbox-org/AesonQQ.hs
@@ -0,0 +1,23 @@
+{-# 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
+            |]
+      }