code: private static JsonObject getObject(JSONArray array, int index)
              throws IOException {
          // We can't just jam an entry into the array without
          //  checking that earlier indexes exist. Also we need
          //  to account for 0 versus 1 based indexing.
  
          // Index changed to 0 based
          if (index < 1) {
              throw new IOException("Invalid index value provided in form data.");
          }
          index -= 1;
  
          // Nice and easy, it already exists
          if (array.size() > index) {
              Object object = array.get(index);
              if (object instanceof JsonObject) {
                  return (JsonObject) object;
              }
              throw new IOException("Non-Object found in array!");
  
          // Slightly more annoying, we need to fill in
          //  all the indices up to this point
          } else {
              for (int i = array.size(); i <= index; i++) {
                  JsonObject object = new JsonObject();
                  array.add(object);
              }
              return (JsonObject) array.get(index);
          }
      }
docs: Get a child JSON Object from an incoming JSON array. If the child does
  not exist it will be created, along with any smaller index values. The
  index is expected to be 1 based (like form data).
  
  It is only valid for form arrays to hold JSON Objects.
  
  @param array The incoming array we are to look inside
  @param index The child index we are looking for (1 based)
  @return JsonObject The child we found or created
  @throws IOException if anything other than an object is found, or an
  invalid index is provided