Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created October 23, 2018 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cemerick/d2f3c279df9cc3ceb827fb64354dcc0a to your computer and use it in GitHub Desktop.
Save cemerick/d2f3c279df9cc3ceb827fb64354dcc0a to your computer and use it in GitHub Desktop.
data Val = Val { foobar :: Int } deriving (Generic, Show)
instance JSON.FromJSON Val where
parseJSON = JSON.genericParseJSON
$ JSON.defaultOptions { JSON.fieldLabelModifier = filter (/= '-') }
{-
$ eitherDecode "{\"foo-bar\": 1}" :: Either String Val
Left "Error in $: key \"foobar\" not present"
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment