title: Data.Aeson encoding optional keys
body: <p>I have the following problem, I have a JSON format with optional keys that I need to generate from my haskell code.</p>
  
  <p>Lets make an example</p>
  
  <pre><code>{-# LANGUAGE DeriveGeneric #-}
  
  import GHC.Generics
  import Data.Aeson
  
  data Person = {
      name :: String,
      shoeSize :: Maybe Int,
      favoriteColor :: Maybe String,
      favoriteFood :: Maybe StringC
  } deriving (show, eq, generic)
  
  instance ToJSON Person -- Generic instance
  </code></pre>
  
  <p>now, if I try encoding a Person without a shoesize I still get a key "shoeSize" set to null, what is the Aeson way of making keys optional in <em>encoding</em></p>
  
  <p>edit, example of an encode</p>
  
  <pre><code>encode $ Person "windwarrior" Nothing "green" Nothing
  </code></pre>
  
  <p>should result in</p>
  
  <pre><code>{"name":"windwarrior", "favoriteColor":"green"}
  </code></pre>