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)