diff --git a/Data/Aeson/AutoType/Alternative.hs b/Data/Aeson/AutoType/Alternative.hs
new file mode 100644
--- /dev/null
+++ b/Data/Aeson/AutoType/Alternative.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE ViewPatterns #-}
+module Data.Aeson.AutoType.Alternative(
+    Alt(..)
+  , toEither, fromEither
+  ) where
+
+import Data.Aeson
+import Control.Applicative
+
+data Alt a b = FirstAlt  a
+             | SecondAlt b
+  deriving(Show,Eq,Ord)
+
+toEither :: Alt a b -> Either a b
+toEither (FirstAlt  a) = Left  a
+toEither (SecondAlt b) = Right b
+
+fromEither :: Either a b -> Alt a b
+fromEither (Left  a) = FirstAlt  a
+fromEither (Right b) = SecondAlt b
+
+instance (ToJSON a, ToJSON b) => ToJSON (Alt a b) where
+    toJSON (FirstAlt  a) = toJSON a
+    toJSON (SecondAlt b) = toJSON b
+    {-# INLINE toJSON #-}
+
+instance (FromJSON a, FromJSON b) => FromJSON (Alt a b) where
+    parseJSON input = (FirstAlt  <$> parseJSON input) <|>
+                      (SecondAlt <$> parseJSON input) <|>
+                      fail ("Neither alternative was found for: " ++ show input)
+    {-# INLINE parseJSON #-}
diff --git a/Data/Aeson/AutoType/CodeGen.hs b/Data/Aeson/AutoType/CodeGen.hs
--- a/Data/Aeson/AutoType/CodeGen.hs
+++ b/Data/Aeson/AutoType/CodeGen.hs
@@ -37,6 +37,7 @@
   ,"import           System.Environment (getArgs)"
   ,"import           Control.Monad      (forM_, mzero)"
   ,"import           Control.Applicative"
+  ,"import           Data.Aeson.AutoType.Alternative"
   ,"import           Data.Aeson(decode, Value(..), FromJSON(..), ToJSON(..),"
   ,"                            (.:), (.:?), (.!=), (.=), object)"
   ,"import           Data.Text (Text)"
diff --git a/Data/Aeson/AutoType/Format.hs b/Data/Aeson/AutoType/Format.hs
--- a/Data/Aeson/AutoType/Format.hs
+++ b/Data/Aeson/AutoType/Format.hs
@@ -155,7 +155,7 @@
   where
     mkUnion []       = emptyTypeRepr
     mkUnion nonEmpty = foldr1 mkEither nonEmpty
-      where mkEither a b = Text.concat ["Either (", a, ") (", b, ")"]
+      where mkEither a b = Text.concat ["Alt (", a, ") (", b, ")"]
 formatType (TArray a)                        = do inner <- formatType a
                                                   return $ Text.concat ["[", inner, "]"]
 formatType (TObj   o)                        = do ident <- genericIdentifier
diff --git a/changelog.md b/changelog.md
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,10 @@
 Changelog
 =========
+    0.2.4.0  Nov 2014
+
+        * To assure proper treatment of unions,
+          I make them with Data.Aeson.AutoType.Alternative type instead of Either.
+
     0.2.3.0  Nov 2014
 
         * Explicit JSON parser generation to avoid conflicts between Haskell keywords and field names.
diff --git a/json-autotype.cabal b/json-autotype.cabal
--- a/json-autotype.cabal
+++ b/json-autotype.cabal
@@ -1,6 +1,6 @@
 -- Build information for the package.
 name:                json-autotype
-version:             0.2.3.0
+version:             0.2.4.0
 synopsis:            Automatic type declaration for JSON input data
 description:         Generates datatype declarations with Aeson's "FromJSON" instances
                      from a set of example ".json" files.
@@ -38,21 +38,55 @@
   type:     git
   location: https://github.com/mgajda/json-autotype.git
 
-executable json-autotype
-  main-is:             GenerateJSONParser.hs
-  other-modules:       Data.Aeson.AutoType.Type
+library
+  exposed-modules:     Data.Aeson.AutoType.Type
                        Data.Aeson.AutoType.Extract
                        Data.Aeson.AutoType.Format
                        Data.Aeson.AutoType.Pretty
                        Data.Aeson.AutoType.CodeGen
+                       Data.Aeson.AutoType.Alternative
+  other-extensions:    TemplateHaskell,
+                       ScopedTypeVariables,
+                       OverloadedStrings,
+                       FlexibleInstances,
+                       MultiParamTypeClasses,
+                       DeriveDataTypeable,
+                       DeriveGeneric,
+                       RecordWildCards
+  other-modules:
                        -- internal module
                        Data.Aeson.AutoType.Util
+  build-depends:       base                 >=4.3  && <4.8,
+                       GenericPretty        >=1.2  && <1.3,
+                       MissingH             >=1.2  && <1.3,
+                       aeson                >=0.7  && <0.9,
+                       bytestring           >=0.9  && <0.11,
+                       containers           >=0.3  && <0.6,
+                       filepath             >=1.3  && <1.4,
+                       hashable             >=1.2  && <1.3,
+                       hflags               >=0.4  && <0.5,
+                       lens                 >=4.1  && <4.5,
+                       mtl                  >=2.1  && <2.2,
+                       pretty               >=1.1  && <1.3,
+                       process              >=1.2  && <1.4,
+                       scientific           >=0.3  && <0.5,
+                       text                 >=1.1  && <1.3,
+                       uniplate             >=1.6  && <1.7,
+                       unordered-containers >=0.2  && <0.3,
+                       vector               >=0.9  && <0.11
+  default-language:    Haskell2010
+
+executable json-autotype
+  main-is:             GenerateJSONParser.hs
+  other-modules:       Data.Aeson.AutoType.Util
   other-extensions:    TemplateHaskell,
                        ScopedTypeVariables,
                        OverloadedStrings,
                        FlexibleInstances,
                        MultiParamTypeClasses,
-                       DeriveDataTypeable
+                       DeriveDataTypeable,
+                       DeriveGeneric,
+                       RecordWildCards
   build-depends:       base                 >=4.3  && <4.8,
                        GenericPretty        >=1.2  && <1.3,
                        MissingH             >=1.2  && <1.3,
