aboutsummaryrefslogtreecommitdiff
path: root/src/server/Json.hs
blob: bd5ac3e3cf898282a75d2103ee2c9fc92349d7d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{-# LANGUAGE OverloadedStrings #-}

module Json
  ( jsonError
  , jsonObject
  ) where

import Web.Scotty

import Network.HTTP.Types.Status (badRequest400)

import qualified Data.Aeson.Types as Json
import qualified Data.HashMap.Strict as M
import Data.Text (Text)

jsonError :: Text -> ActionM ()
jsonError msg = do
  status badRequest400
  jsonObject [("error", Json.String msg)]

jsonObject :: [(Text, Json.Value)] -> ActionM ()
jsonObject = json . Json.Object . M.fromList