title: How to write a Play JSON writes converter for a case class with a single nullable member
body: <p>In Play 2.3, I have a case class with a single optional double member:</p>
  
  <pre><code>case class SomeClass(foo: Option[Double])
  </code></pre>
  
  <p>I need a JSON write converter that handles the member as nullable:</p>
  
  <pre><code>implicit val someClassWrite: Writes[SomeClass] = ???
  </code></pre>
  
  <p>The <a href="https://www.playframework.com/documentation/2.3.x/ScalaJsonCombinators" rel="noreferrer">Play docs provide an example</a>:</p>
  
  <pre><code>case class DisplayName(name:String)
  implicit val displayNameWrite: Writes[DisplayName] = Writes {
    (displayName: DisplayName) =&gt; JsString(displayName.name)
  }
  </code></pre>
  
  <p>But sadly I can't figure out how to do this for 1) a single nullable and 2) a double. Any ideas? Thanks.</p>
  
  <p><strong>Update #1:</strong> The only solution I can come up with is this:</p>
  
  <pre><code>implicit val someClassWrite: Writes[SomeClass] = Writes {
    (someClass: SomeClass) =&gt; someClass.foo match {
      case Some(f) =&gt; JsNumber(BigDecimal(f))
      case _ =&gt; JsNull
  }
  </code></pre>
  
  <p><strong>Update #2:</strong> Ignore my solution. Travis Brown's is the one.</p>