Why use XML to Haskell instead of JSON to Haskell?
Choose XML to Haskell when the source payload is XML and the generated record types need to reflect nested elements and repeated nodes rather than JSON object conventions.
Generate Haskell data types from XML samples when your functional service or CLI still parses XML documents into typed records.
<user>
<id>101</id>
<name>Ada Lovelace</name>
<active>true</active>
<roles>
<role>admin</role>
<role>editor</role>
</roles>
<profile>
<email>ada@example.com</email>
<score>9.8</score>
</profile>
</user>
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics (Generic)
import Data.Text (Text)
import Data.Aeson (FromJSON, ToJSON)
data UserModel = UserModel
{ id :: Int
, name :: Text
, active :: Bool
}
deriving (Show, Eq, Generic)
instance FromJSON UserModel
instance ToJSON UserModel
Choose XML to Haskell when the source payload is XML and the generated record types need to reflect nested elements and repeated nodes rather than JSON object conventions.
Yes. Nested XML elements become additional Haskell record types, and repeated nodes are inferred into typed list fields from the parsed XML sample.