code: private int readOptionalInt(JSONObject json, String key) {
  
          try {
              String str = json.getString(key);
              return Integer.valueOf(str).intValue();
          } catch (NumberFormatException | JSONException e) {
              LOG.debug("Reading optional JSON int failed. Default to provided default value.", e);
          }
          return 0;
      }
docs: Read an optional int value (stored as string) form a JSON Object.
  @param json the JSON object to read from.
  @param key the key for the int value in the provided JSON object.
  @return the int or 0 if reading the int fails.