input: Write a function that creates a Flask API to fetch data from an SQLite database and returns the data in JSON format. The function should include a route that executes an SQL query to fetch all users from the 'users' table. If the database connection is successful, the function should return the users data in JSON format.
  assert index(sqlite3.connect('test_database.db'))==200
  assert index(sqlite3.connect('nonexistent_database.db'))==500
  assert index(sqlite3.connect('empty_database.db'))==[]
  assert index(sqlite3.connect('invalid_database.db'))==None
output: 
  def index(db_connection):
      try:
          cursor = db_connection.cursor()
          cursor.execute("SELECT * FROM users")
          users = cursor.fetchall()
          return jsonify(users)
      except Exception as e:
          return jsonify({"error": str(e)}), 500
  