Daniel Diaz  committed 075fc7e

Added FromJSON and ToJSON instances for Data.Tree.

The instances reuse the instance code for tuples.

  • Participants
  • Parent commits 7a2d130

Comments (0)

Files changed (1)

File Data/Aeson/Types/Class.hs

 import qualified Data.IntSet as IntSet
 import qualified Data.Map as M
 import qualified Data.Set as Set
+import qualified Data.Tree as Tree
 import qualified Data.Text as T
 import qualified Data.Text.Lazy as LT
 import qualified Data.Vector as V
 instance (FromJSON v) => FromJSON (H.HashMap String v) where
     parseJSON = fmap (mapKey unpack) . parseJSON
+instance (ToJSON v) => ToJSON (Tree.Tree v) where
+    toJSON (Tree.Node root branches) = toJSON (root,branches)
+instance (FromJSON v) => FromJSON (Tree.Tree v) where
+    parseJSON j = uncurry Tree.Node <$> parseJSON j
 instance ToJSON Value where
     toJSON a = a
     {-# INLINE toJSON #-}