@@ -325,12 +325,19 @@ instance (FromJSON a) => FromJSON (Maybe a) where
325325 {-# INLINE parseJSON #-}
326326
327327instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
328− toJSON (Left a) = toJSON a
329− toJSON (Right b) = toJSON b
328+ toJSON (Left a) = Array (V.fromList [String "Left", toJSON a])
329+ toJSON (Right b) = Array (V.fromList [String "Right", toJSON b])
330330 {-# INLINE toJSON #-}
331331
332332instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
333− parseJSON a = Left <$> parseJSON a <|> Right <$> parseJSON a
333+ parseJSON v@(Array vec) =
334+ if V.length vec /= 2
335+ then typeMismatch "Either a b" v
336+ else case vec V.! 0 of
337+ "Left" -> Left <$> parseJSON (vec V.! 1)
338+ "Right" -> Right <$> parseJSON (vec V.! 1)
339+ _ -> typeMismatch "Either a b" v
340+ parseJSON v = typeMismatch "Either a b" v
334341 {-# INLINE parseJSON #-}
335342
336343instance ToJSON Bool where