code: public static boolean getBoolean(JSONObject json, String key, boolean defaultValue) {
          if (json.containsKey(key)) {
              boolean result;
              try {
                  result = json.getBoolean(key);
              } catch (JSONException ex) {
                  result = defaultValue;
              }
              return result;
          } else {
              return defaultValue;
          }
      }
docs: Returns the value of a JSON property as a boolean if it exists and boolean value
  otherwise returns the defaultValue.
  @param json the JSONObject to check.
  @param key the key.
  @param defaultValue the value to return if the key is missing or not boolean value.
  @return the value for the key as a boolean.