code: private void sortChildren(JSONObject root) throws JSONException {
      JSONArray children = root.getJSONArray("children");
      List<JSONObject> childrenSorted = new ArrayList<JSONObject>(children.
              length());
  
      for (int i = 0; i < children.length(); i++) {
        childrenSorted.add(children.getJSONObject(i));
      }
  
      Collections.sort(childrenSorted, new Comparator<Object>() {
        @Override
        public int compare(Object o1, Object o2) {
          int o1IdxLeft = 0;
          int o1IdxRight = 0;
          int o2IdxLeft = 0;
          int o2IdxRight = 0;
          try {
            o1IdxLeft = ((JSONObject) o1).getJSONObject("data").getInt(
                    SENTENCE_LEFT);
            o1IdxRight = ((JSONObject) o1).getJSONObject("data").getInt(
                    SENTENCE_RIGHT);
            o2IdxLeft = ((JSONObject) o2).getJSONObject("data").getInt(
                    SENTENCE_LEFT);
            o2IdxRight = ((JSONObject) o2).getJSONObject("data").getInt(
                    SENTENCE_RIGHT);
          } catch (JSONException ex) {
            log.error("Could not compare sentence indizes.", ex);
          }
  
          if (o1IdxLeft + o1IdxRight > o2IdxLeft + o2IdxRight) {
            return 1;
          }
  
          if (o1IdxLeft + o1IdxRight == o2IdxLeft + o2IdxRight) {
            return 0;
          } else {
            return -1;
          }
        }
      });
  
      children = new JSONArray(childrenSorted);
      root.put("children", children);
    }
docs: Sorts the children of root by the the sentence indizes. Since the sentence
  indizes are based on the token indizes, some sentences have no sentences
  indizes, because sometimes token nodes are out of context.
  
  A kind of insertion sort would be better than the used mergesort.
  
  And it is a pity that the {@link JSONArray} has no interface to sort the
  underlying {@link Array}.