こんな感じで定義してあるので
instance (JSON a) => JSON [a] where toJValue = undefined fromJValue = undefined instance (JSON a) => JSON [(String, a)] where toJValue = undefined fromJValue = undefined instance (JSON a) => JSON (JObj a) where toJValue = JObject . JObj . map (second toJValue) . fromJObj fromJValue (JObject (JObj o)) = whenRight JObj (mapEithers unwrap o) where unwrap (k,v) = whenRight ((,) k) (fromJValue v) fromJValue _ = Left "not a JSON object" instance (JSON a) => JSON (JAry a) where toJValue = jaryToJValue fromJValue = jaryFromJValue newtype JAry a = JAry { fromJAry :: [a] } deriving (Eq, Ord, Show) newtype JObj a = JObj { fromJObj :: [(String, a)] } deriving (Eq, Ord, Show)
アレイとオブジェクトをJValue型にするために
*JSONClass> toJValue . JObj $ [("test", 1)] JObject (JObj {fromJObj = [("test",JNumber 1.0)]}) *JSONClass> toJValue . JAry $ [1,2,3] JArray (JAry {fromJAry = [JNumber 1.0,JNumber 2.0,JNumber 3.0]})
ってやらないといけないのが、ちょっと引っかかる。動かすとこまでは書いてないからなぁ。