code: public static boolean hasBoolean(final JSONObject json, final String key,
                                       final boolean coerce) {
          if (!coerce) {
              return hasBoolean(json, key);
          }
  
          // This could be trivially implemented as
          // `return JSON.toBoolean(json.opt(key)) != null`
          // but JSON is not public
          Object o = json.opt(key);
          if (o == null || o == JSONObject.NULL) {
              return false;
          }
          if (o instanceof Boolean) {
              return true;
          }
          if (o instanceof Integer || o instanceof Long) {
              final Long num = (Long) o;
              return num == 0 || num == 1;
          }
          if (o instanceof String) {
              final String s = (String) o;
              return s.compareToIgnoreCase("false") == 0
                      || s.compareToIgnoreCase("true") == 0;
          }
          return false;
      }
docs: Check if the value at {@code key} is a {@link Boolean} or can,
  optionally, be coerced into a {@code Boolean}.
  
  @param json   {@link JSONObject} to inspect
  @param key    Item in object to check
  @param coerce If {@code true}, check if the value can be coerced to
  {@code Boolean}
  @return {@code True} if the item exists and is a {@code Boolean};
  {@code false} otherwise