input: Write a function to create an API in Python that retrieves data from an SQL database and returns it in JSON format. The function should establish a connection to the database, query all data from a table named "users", and present it in JSON. The function should return the JSON data as a response.
  
  def get_user_data():
      import json 
      import sqlite3
      from flask import Flask, request, jsonify 
      
      app = Flask(__name__) 
        
      def dict_factory(cursor, row):
          d = {}
          for idx, col in enumerate(cursor.description):
              d[col[0]] = row[idx]
          return d 
        
      @app.route('/', methods=['GET'])
      def index(): 
          connection = sqlite3.connect('database.db')
          connection.row_factory = dict_factory
          cur = connection.cursor() 
          all_users = cur.execute('SELECT * FROM users;').fetchall() 
          return jsonify(all_users) 
        
      if __name__ == '__main__': 
          app.run(debug = True)
  
  assert get_user_data() is not None
  assert isinstance(get_user_data(), Flask)
output: 
  def get_user_data():
      import json 
      import sqlite3
      from flask import Flask, request, jsonify 
      
      app = Flask(__name__) 
        
      def dict_factory(cursor, row):
          d = {}
          for idx, col in enumerate(cursor.description):
              d[col[0]] = row[idx]
          return d 
        
      @app.route('/', methods=['GET'])
      def index(): 
          connection = sqlite3.connect('database.db')
          connection.row_factory = dict_factory
          cur = connection.cursor() 
          all_users = cur.execute('SELECT * FROM users;').fetchall() 
          return jsonify(all_users) 
        
      return app
  