input: Write a python function to fetch all data from a MySQL database table and convert it into JSON format.
  assert fetch_data_to_json("localhost", "yourusername", "yourpassword", "test", "users") == '[...]'
  assert fetch_data_to_json("localhost", "username", "password", "sample_db", "employees") == '[...]'
  assert fetch_data_to_json("localhost", "admin", "admin123", "company", "staff") == '[...]'
output: import mysql.connector
  import json
  
  def fetch_data_to_json(host, user, password, database, table):
      # Establishing connection to the database
      conn = mysql.connector.connect(
          host=host,
          user=user,
          password=password,
          database=database
      )
      
      cursor = conn.cursor(dictionary=True)
      
      # Fetching data from the specified table
      cursor.execute(f"SELECT * FROM {table}")
      rows = cursor.fetchall()
      
      # Closing the connection
      cursor.close()
      conn.close()
      
      # Converting fetched data to JSON format
      return json.dumps(rows)