code: private static JSONArray getArray(JsonObject object, String key)
              throws IOException {
          // Get the existing one
          if (object.containsKey(key)) {
              Object existing = object.get(key);
              if (!(existing instanceof JSONArray)) {
                  throw new IOException("Invalid field structure, '" + key +
                          "' expected to be an array, but incompatible "
                          + "data type already present.");
              }
              return (JSONArray) existing;
  
          // Or add a new one
          } else {
              JSONArray newObject = new JSONArray();
              object.put(key, newObject);
              return newObject;
          }
      }
docs: Get a child JSON Array from an incoming JSON object. If the child does
  not exist it will be created.
  
  @param object The incoming object we are to look inside
  @param key The child node we are looking for
  @return JSONArray The child we found or created
  @throws IOException if there is a type mismatch on existing data