Add a connection string to appsettings.json

In appsettings.json, we can use the ConnectionStrings object to add a key/value property with a connection string.

This allows us to connect our ASP.NET Core web app to a SQL Server database.

We have this connection string that we wish to add to our ASP.NET Core app.

Server=localhost; Database=MyDatabase; Trusted_Connection=true; Trust Server Certificate=true; MultipleActiveResultSets=true; Integrated Security=true;

Our appsettings.json file looks like this:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

How would we add this connection string to the appsettings.json file with a MyDatabaseDbContext key?