Conditional JSON decoding based on a field value
<p>I have a need to decode JSON into an elm type like below:</p>

<p>Type</p>

<pre><code>type User = Anonymous | LoggedIn String

type alias Model =
  { email_id : User
  , id : Id
  , status : Int
  , message : String
  , accessToken : AccessToken
  }
</code></pre>

<p><strong>JSON Message 1</strong></p>

<pre><code>{
  "status": 0,
  "message": "Error message explaining what happened in server"
}
</code></pre>

<p>into type value</p>

<pre><code>Model {
   "email_id": Anonymous
   , id: 0
   , status: 0
   , message: json.message
   , accessToken: ""
}
</code></pre>

<p><strong>JSON Message 2</strong></p>

<pre><code>{
  "status": 1,
  "email_id": "asdfa@asdfa.com"
  "token": "asdfaz.adfasggwegwegwe.g4514514ferf"
  "id": 234
}
</code></pre>

<p>into type value</p>

<pre><code>Model {
   "email_id": LoggedIn json.email_id
   , id: json.id
   , status: json.status
   , message: ""
   , accessToken: json.token
}
</code></pre>

<p><strong>Decoder information</strong></p>

<p>Above, "message" is not always present and email_id/id/token are always not present.</p>

<p>How to do this type of conditional decoding in elm</p>