title: Transform JSON tree to other format (XML, CSV etc.) recursively with circe
body: <p>In order to transform JSON nodes to an <em>other</em> format than JSON (like XML, CSV etc.) with circe I came up with a solution where I had to access internal data structures of circe. </p>
  
  <p>This is my working sample that transforms JSON to a XML String (not perfect but you get the idea):</p>
  
  <pre><code>package io.circe
  
  import io.circe.Json.{JArray, JBoolean, JNull, JNumber, JObject, JString}
  import io.circe.parser.parse
  
  object Sample extends App {
  
    def transformToXMLString(js: Json): String = js match {
      case JNull =&gt; ""
      case JBoolean(b) =&gt; b.toString
      case JNumber(n) =&gt; n.toString
      case JString(s) =&gt; s.toString
      case JArray(a) =&gt; a.map(transformToXMLString(_)).mkString("")
      case JObject(o) =&gt; o.toMap.map {
        case (k, v) =&gt; s"&lt;${k}&gt;${transformToXMLString(v)}&lt;/${k}&gt;"
      }.mkString("")
    }
  
    val json =
      """{
        | "root": {
        |  "sampleboolean": true,
        |  "sampleobj": {
        |    "anInt": 1,
        |    "aString": "string"
        |  },
        |  "objarray": [
        |     {"v1": 1},
        |     {"v2": 2}
        |  ]
        | }
        |}""".stripMargin
  
    val res = transformToXMLString(parse(json).right.get)
    println(res)
  }
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>&lt;root&gt;&lt;sampleboolean&gt;true&lt;/sampleboolean&gt;&lt;sampleobj&gt;&lt;anInt&gt;1&lt;/anInt&gt;&lt;aString&gt;string&lt;/aString&gt;&lt;/sampleobj&gt;&lt;objarray&gt;&lt;v1&gt;1&lt;/v1&gt;&lt;v2&gt;2&lt;/v2&gt;&lt;/objarray&gt;&lt;/root&gt;
  </code></pre>
  
  <p>That's all fine and dandy if the low-level JSON objects (like <code>JBoolean, JString, JObject</code> etc.) were not <em>package private</em> in circe which only makes this code above work if it is put in package <code>package io.circe</code>.</p>
  
  <p>How can you achieve the same result like above using the public circe API?</p>