private void writeJSON(Object value) throws JSONException {
        if (JSONObject.NULL.equals(value)) {
            write(zipNull, 3);
        } else if (Boolean.FALSE.equals(value)) {
            write(zipFalse, 3);
        } else if (Boolean.TRUE.equals(value)) {
            write(zipTrue, 3);
        } else {
            if (value instanceof Map) {
                value = new JSONObject((Map) value);
            } else if (value instanceof Collection) {
                value = new JSONArray((Collection) value);
            } else if (value.getClass().isArray()) {
                value = new JSONArray(value);
            }
            if (value instanceof JSONObject) {
                write((JSONObject) value);
            } else if (value instanceof JSONArray) {
                write((JSONArray) value);
            } else {
                throw new JSONException("Unrecognized object");
            }
        }
    }