blob: 8dda3499137406e3b538b30b3d5bc64fb27bad23 (
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
24
|
module Data.JLD.Model.ListObject (isListObject, isNotListObject, toListObject) where
import Data.JLD.Prelude
import Data.JLD.Model.Keyword (Keyword (..))
import Data.Aeson (Value (..))
import Data.Aeson.KeyMap qualified as KM
import Data.Vector qualified as V
isListObject :: Value -> Bool
isListObject (Object o) =
KM.member (show KeywordList) o
&& ( KM.size o == 1
|| (KM.size o == 2 && KM.member (show KeywordIndex) o)
)
isListObject _ = False
isNotListObject :: Value -> Bool
isNotListObject = isListObject .> not
toListObject :: Value -> Value
toListObject value@(Array _) = Object <| KM.singleton (show KeywordList) value
toListObject value = Object <| KM.singleton (show KeywordList) (Array <| V.singleton value)
|