Commits

Bryan O'Sullivan  committed 83b5119 Merge

Merge pull request #153 from danidiaz/master

Added FromJSON and ToJSON instances for Data.Tree.

  • Participants
  • Parent commits 07032a4, 075fc7e

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 #-}