title: How to update JSONArray with new values?
body: <p>The below is JSON object which is retrieved from database (input).</p>
  <pre><code>{&quot;Pickup Date End&quot;:[&quot;{\&quot;date\&quot;:\&quot;2020-12-30T14:15:00\&quot;,\&quot;tzId\&quot;:\&quot;Asia/Calcutta\&quot;,\&quot;tzCode\&quot;:\&quot;IST\&quot;}&quot;,&quot;{\&quot;date\&quot;:\&quot;2020-12-31T14:15:00\&quot;,\&quot;tzId\&quot;:\&quot;Asia/Calcutta\&quot;,\&quot;tzCode\&quot;:\&quot;IST\&quot;}&quot;],
  &quot;Pickup Date Start&quot;:[&quot;{\&quot;date\&quot;:\&quot;2020-12-30T14:15:00\&quot;,\&quot;tzId\&quot;:\&quot;Asia/Calcutta\&quot;,\&quot;tzCode\&quot;:\&quot;IST\&quot;}&quot;,&quot;{\&quot;date\&quot;:\&quot;2020-12-31T14:15:00\&quot;,\&quot;tzId\&quot;:\&quot;Asia/Calcutta\&quot;,\&quot;tzCode\&quot;:\&quot;IST\&quot;}&quot;]}
  </code></pre>
  <p>I did some required customization (in <em>Pickup Date End</em> JSONObject) and tried to put updated values in the same JSONArray which as below (output)</p>
  <pre><code>{&quot;Pickup Date End&quot;:[{&quot;date&quot;:&quot;2020-12-30T02:45:00&quot;,&quot;tzId&quot;:&quot;Asia/Calcutta&quot;,&quot;tzCode&quot;:&quot;IST&quot;},{&quot;date&quot;:&quot;2020-12-31T02:45:00&quot;,&quot;tzId&quot;:&quot;Asia/Calcutta&quot;,&quot;tzCode&quot;:&quot;IST&quot;}],&quot;Pickup Date Start&quot;:[&quot;{&quot;date&quot;:&quot;2020-12-30T02:45:00&quot;,&quot;tzId&quot;:&quot;Asia/Calcutta&quot;,&quot;tzCode&quot;:&quot;IST&quot;},{&quot;date&quot;:&quot;2020-12-31T02:45:00&quot;,&quot;tzId&quot;:&quot;Asia/Calcutta&quot;,&quot;tzCode&quot;:&quot;IST&quot;}&quot;]}
  </code></pre>
  <p>But this gives an error which may be due to \ is not present in updated JSONObject.
  <strong>Can someone please suggest how to apply escape i.e. \ character for JSONObjcet in Java?</strong></p>
  <p>Code is</p>
  <pre><code>try {
        TimeZone siteTz = TimeZoneUtil.getSiteTimeZoneBySiteSysId(shipFromSiteId.longValue(), DvceContext.getInstanceAdminContext());
       if (changesObject != null) {
         JSONObject changes = (JSONObject) changesObject.get(&quot;Changes&quot;);
         if (changes.has(&quot;Pickup Date End&quot;)) {
           JSONArray valueArray = (JSONArray) changes.get(&quot;Pickup Date End&quot;);
           JSONObject oldJson = new JSONObject(valueArray.get(0).toString());
           JSONObject newJson = new JSONObject( valueArray.get(1).toString());
           
           Calendar oldCalendar = DateUtils.getFormattedDate((String) oldJson.get(&quot;date&quot;), &quot;yyyy-MM-dd'T'HH:mm:ss&quot;);
           Calendar newCalendar = DateUtils.getFormattedDate((String) newJson.get(&quot;date&quot;), &quot;yyyy-MM-dd'T'HH:mm:ss&quot;);             
           oldCalendar = TimeZoneUtil.convertTimeToTimeZone(oldCalendar, siteTz);
           newCalendar = TimeZoneUtil.convertTimeToTimeZone(newCalendar, siteTz);
           
           DateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd'T'HH:mm:ss&quot;);
           dateFormat.setTimeZone(siteTz);
           
           oldJson.put(&quot;date&quot;, dateFormat.format(oldCalendar.getTime()));
           newJson.put(&quot;date&quot;, dateFormat.format(newCalendar.getTime()));
           JSONArray newValuesArray = new JSONArray();
           newValuesArray.put(0, oldJson);
           newValuesArray.put(1, newJson);
           changes.put(&quot;Pickup Date End&quot;, newValuesArray);
           changesObject.put(&quot;Changes&quot;, changes);
           //row.setValue(changesColIndex, changesObject.toString());
         }
       }          
      }
      catch (Exception e) {
        // TODO either LOG the exception or re-throw, but not both
      }
  </code></pre>