title: Transform Json with circe
body: <p>Assuming the following json payload </p>
  
  <pre><code>val json = """{
    "choices" : [
      {
        "name" : "A"
      },
      {
        "name" : "B"
      },
      {
        "name" : "C"
      },
      {
        "name" : "D"
      }
    ],
    "domain" : "Quizz",
    "level" : "Test",
    "mandatory": true
  }"""
  </code></pre>
  
  <p>How do I transform it to </p>
  
  <pre><code>val json = """{
    "value":"B",
    "domain" : "Quizz",
    "level" : "Test",
  }"""
  </code></pre>
  
  <p>where the "B" is randomly selected from the available choices  ?</p>
  
  <p>This is what I have got so far :</p>
  
  <pre><code>val cursor = parse(json).getOrElse(Json.Null).cursor
  for{
    noMandatory&lt;- cursor.downField("mandatory").flatMap(_.delete).map(_.top)
    withEmptyValue = noMandatory.deepMerge(Json.obj("value"-&gt;Json.Null))
   }yield withEmptyValue
  </code></pre>
  
  <p>This drops the unused "mandatory" field and inserts an empty "value" field.  Getting a random value from the array and placing it in "value" escapes me though.</p>
  
  <p>-- edit </p>
  
  <p>I have tried using hcursor which makes the above clearer (to me anyway)</p>
  
  <pre><code>val cursor = parse(json).getOrElse(Json.Null).hcursor
  
  val noMandatory = cursor.downField("mandatory").delete
  val withEmptyValue = noMandatory.withFocus(_.deepMerge(Json.obj("value"-&gt;Json.Null)))
  </code></pre>
  
  <p>(I am using circe 0.5.1 in the above examples)</p>