title: How to add ArrayList to JsonObject in Kotlin
body: <blockquote>
  <p>PaymentDetails class</p>
  </blockquote>
  <pre><code>data class PaymentDetails(
  val type:String,
  val bank: String,
  val branch: String,
  val account_no: String,
  val cheque_date:String,
  val return_type:Boolean,
  val cheque_no:String,
  val return_cheque_no:String,
  val amount:String)
  </code></pre>
  <blockquote>
  <p>Adding to Json Object</p>
  </blockquote>
  <pre><code>  var obj = JSONObject(myPreference!!.getJsonObject());
      Log.e(&quot;test Object add&quot;, obj.get(&quot;reciptDetail&quot;).toString())
      
      val paymentDetails : PaymentDetails = PaymentDetails(type, &quot;&quot;, &quot;&quot;, &quot;&quot;,&quot;&quot;,false,&quot;&quot;,&quot;&quot;,viewPaymentCash!!.etxt_amount.text.toString())
      myList.add(paymentDetails)
      val jsArray = Gson().toJson(myList)
      var obj2 = JSONObject(obj.get(&quot;reciptDetail&quot;).toString());
      
      obj2.remove(&quot;payment_details&quot;)
      obj2.put(&quot;payment_details&quot;,jsArray)
      
      Log.e(&quot;cash Object&quot;, obj2.toString())
  </code></pre>
  <p>Here I tried to add new Arraylist to existing JsonObject. Issue is that the final Json object is not what I am expecting. How can I solve that issue? Below I attched what I expected and what I got.</p>
  <p>Expected</p>
  <pre><code>{&quot;receiptNo&quot;:&quot;fggff&quot;,&quot;todate&quot;:&quot;4\/12\/2018&quot;,&quot;remark&quot;:&quot;&quot;,&quot;payment_details&quot;:[{&quot;account_no&quot;:&quot; &quot;,&quot;amount&quot;:&quot;600&quot;,&quot;bank&quot;:&quot;&quot;,&quot;branch&quot;:&quot;&quot;,&quot;cheque_date&quot;:&quot;&quot;,&quot;cheque_no&quot;:&quot;&quot;,&quot;return_cheque_no&quot;:&quot;&quot;,&quot;type&quot;:&quot;Cash&quot;,&quot;return_type&quot;:false}]}
  </code></pre>
  <p>What I got from above code</p>
  <pre><code>{&quot;receiptNo&quot;:&quot;fggff&quot;,&quot;todate&quot;:&quot;4\/12\/2018&quot;,&quot;remark&quot;:&quot;&quot;,&quot;payment_details&quot;:&quot;[{\&quot;account_no\&quot;:\&quot;\&quot;,\&quot;amount\&quot;:\&quot;600\&quot;,\&quot;bank\&quot;:\&quot;\&quot;,\&quot;branch\&quot;:\&quot;\&quot;,\&quot;cheque_date\&quot;:\&quot;\&quot;,\&quot;cheque_no\&quot;:\&quot;\&quot;,\&quot;return_cheque_no\&quot;:\&quot;\&quot;,\&quot;type\&quot;:\&quot;Cash\&quot;,\&quot;return_type\&quot;:false}]&quot;}
  </code></pre>