I was trying this but ran into a bit of trouble. Are you super attached to that data structure? I would expect a radix tree as you've described it to look more like this:
data RadixTree = Node [(Text, RadixTree)] | Leaf Times
data Times = Times (Maybe Int) (Maybe Int)
In which case it is much easier to write the json instances. From there you shouldn't have too much of a problem writing a recursive function to do the rest, without dealing with all the aeson stuff at the same time. Here's what I ended up with (I think it could be cleaned up a bit).
import Control.Monad
import Data.Text as T
import Data.Aeson
import Data.HashMap.Strict as HM
import Data.Vector as V hiding (mapM)
data RadixTree = Node [(Text, RadixTree)] | Leaf Times deriving Show
data Times = Times (Maybe Int) (Maybe Int) deriving Show
instance FromJSON RadixTree where
parseJSON (Object o) = do
let els = HM.toList o
contents <- mapM (\(t,v) -> do v' <- parseJSON v; return (t, v')) (HM.toList o)
return $ Node contents
parseJSON a@(Array _) = Leaf <$> parseJSON a
parseJSON _ = mzero
instance FromJSON Times where
parseJSON (Array v) | (V.length v) >= 2 =
let v0 = v V.! 0
v1 = v V.! 1
in Times <$> parseJSON v0 <*> parseJSON v1
parseJSON _ = mzero
{-
tree2things :: RadixTree -> [(Text, (Maybe Int, Maybe Int))]
tree2things (Node xs) = _
tree2things (Leaf t) = _
-}