module Recalc.Server.Json where
import Data.Aeson as Json
import Data.Char (toLower)
aesonOptions :: Json.Options
aesonOptions :: Options
aesonOptions =
Options
Json.defaultOptions
{ Json.fieldLabelModifier = labelModifier
, Json.constructorTagModifier = consMap toLower id
, Json.omitNothingFields = True
, Json.allowOmittedFields = True
, Json.rejectUnknownFields = True
}
where
labelModifier :: [Char] -> [Char]
labelModifier [Char]
str
| Char
'\'' Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
str = [Char] -> [Char]
forall a. HasCallStack => [a] -> [a]
tail ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\'') [Char]
str
| Bool
otherwise = [Char]
str
consMap :: (t -> a) -> ([t] -> [a]) -> [t] -> [a]
consMap t -> a
f [t] -> [a]
g (t
x : [t]
xs) = t -> a
f t
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [t] -> [a]
g [t]
xs
consMap t -> a
_ [t] -> [a]
g [] = [t] -> [a]
g []