title: How to convert an Kotlin array of objects into json array with preserving access key names?
body: <p>I have an API which demands the json request to be in specific array form where array object fields are accessed with names which is then posted using Retrofit. Please refer below code:</p>
  <p>Kotlin:</p>
  <pre><code>class RailPoint(
   var railPointId,
   var startTime,
   var endTime
  )
  
  var rails: ArrayList&lt;RailPoint&gt;()
  rails.add(RailPointObject1)
  rails.add(RailPointObject2)
  </code></pre>
  <p>So, after converting above <code>rails</code> array to json, it should yield following result:</p>
  <pre><code>{
    &quot;railPoint[0][railPointId]&quot;: 5,
    &quot;railPoint[0][startTime]&quot;: &quot;&quot;,
    &quot;railPoint[0][endTime]&quot;: &quot;2021-10-19 07:37:19&quot;,
    &quot;railPoint[1][railPointId]&quot;: 1,
    &quot;railPoint[1][startTime]&quot;: &quot;2021-10-19 07:33:37&quot;,
    &quot;railPoint[1][endTime]&quot;: &quot;2021-10-19 07:35:20&quot;,
  }
  </code></pre>
  <p>So, how can I achieve this type of json array form?</p>