title: Unable to remove "\" from the json nested attributes using spark scala
body: <p>I am working on an <code>FHIR</code> resource where I am getting a JSON data like below:</p>
  <pre><code>{
      &quot;appointmentRef&quot;: &quot;Appointment/12213#4200&quot;,
      &quot;encounterLengh&quot;: &quot;2&quot;,
      &quot;billingAccount&quot;: &quot;savingsAccount&quot;,
      &quot;hospitalization&quot;: &quot;{\&quot;preAdmissionIdentifierSystem\&quot;:\&quot;https://system123445.html\&quot;,\&quot;preAdmissionIdentifierValue\&quot;:\&quot;pqr\&quot;,\&quot;origin\&quot;:\&quot;hospital\&quot;,\&quot;admitSourceCode\&quot;:\&quot;outp\&quot;,\&quot;admitSourceReason\&quot;:\&quot;some thing\&quot;,\&quot;eid\&quot;:200,\&quot;destination\&quot;:\&quot;hospital\&quot;}&quot;,
      &quot;resourceType&quot;: &quot;Encounter&quot;,
      &quot;priority&quot;: &quot;abc&quot;,
      &quot;status&quot;: &quot;triaged&quot;,
      &quot;eid&quot;: &quot;200&quot;,
      &quot;subject&quot;: &quot;Patient/435&quot;
  }
  </code></pre>
  <p>So, previously for the attributes which are on the root level like <code>appointmentRef</code> and etc..they also had <code>&quot;\&quot;</code> on the R.H.S which I was able to remove it by my code. However, as it can be seen from the data above that for the nested attributes my code isn't working.</p>
  <pre><code>rowList.groupBy(row =&gt; row.key).foreach(rowList =&gt; {
          import com.google.gson.{Gson, JsonObject}
          val map: Map[String, String] = mutable.Map()
          rowList._2.foreach(row =&gt; {
            LOGGER.debug(s&quot;row == $row&quot;)
            if (Utility.isBlank(row.jsonElementTag)) {
              val convertedObject = new Gson().fromJson(row.value, classOf[JsonObject])
              val itr = convertedObject.entrySet().iterator()
              while (itr.hasNext) {
                val next = itr.next()
                val value = next.getValue.getAsString
                val key = next.getKey
                LOGGER.debug(s&quot;key-- $key value --$value&quot;)
                map.put(key, value)
              }
            }
            else {
              val convertedObject = new Gson().fromJson(row.value, classOf[JsonObject])
              LOGGER.debug(s&quot;convertedObject  == $convertedObject&quot;)
              if (null != map.get(row.jsonElementTag).getOrElse(null)) {
                LOGGER.debug(&quot;map.get(row.jsonElementTag).get === &quot;+row.jsonElementTag +&quot; &quot;+map.get(row.jsonElementTag).get)
                var array: JsonArray = new JsonArray
                val mapElement = new Gson().fromJson(map.get(row.jsonElementTag).get, classOf[JsonObject])
                array.add(mapElement)
                array.add(convertedObject)
                map.put(row.jsonElementTag, array.toString)
              }
              else {
                map.put(row.jsonElementTag, convertedObject.toString)
              }
            }
          })
  </code></pre>
  <p>I am just taking the rows from the data frame and iterating over the rows, taking it as a string, and putting it in key-value pairs. The <code>if</code> loop will run for the parent level attributes and the <code>else-if</code> loop will be executed for the nested attributes.</p>
  <p>I even tried the simpler way of <code>replace(&quot;\&quot;,&quot;&quot;)</code> but it didn't work. So, how do I remove the <code>&quot;\&quot;</code> from the nested attributes?</p>
  <p>My <code>expected</code> output is there should be no <code>&quot;\&quot;</code> in my nested JSON attributes.</p>