module Dialogflow.Util
( toObject
, noNullObjects
) where
import Data.Aeson ( ToJSON
, toJSON
, object
, Value(..)
, Object )
import Data.Aeson.Types (Pair)
toObject :: ToJSON a => a -> Object
toObject :: a -> Object
toObject a
a = case a -> Value
forall a. ToJSON a => a -> Value
toJSON a
a of
Object Object
o -> Object
o
Value
_ -> [Char] -> Object
forall a. HasCallStack => [Char] -> a
error [Char]
"toObject: value isn't an Object"
noNullObjects :: [Pair] -> Value
noNullObjects :: [Pair] -> Value
noNullObjects = [Pair] -> Value
object ([Pair] -> Value) -> ([Pair] -> [Pair]) -> [Pair] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(Text
_,Value
v) -> Value
v Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
Null)