--------------------------------------------------------------------------------
module Data.Aeson.TH.Extended
    ( module Data.Aeson.TH
    , dropPrefixOptions
    ) where


--------------------------------------------------------------------------------
import           Data.Aeson.TH
import           Data.Char     (isUpper, toLower)


--------------------------------------------------------------------------------
dropPrefixOptions :: Options
dropPrefixOptions :: Options
dropPrefixOptions = Options
defaultOptions
    { fieldLabelModifier = dropPrefix
    }
  where
    dropPrefix :: [Char] -> [Char]
dropPrefix [Char]
str = case (Char -> Bool) -> [Char] -> ([Char], [Char])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Char -> Bool
isUpper [Char]
str of
        ([Char]
_, (Char
y : [Char]
ys)) -> Char -> Char
toLower Char
y Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
ys
        ([Char], [Char])
_             -> [Char]
str