liveBook · Manning

Appsettings.json

As explained in ASP.NET Core in Action, 3e

appsettings.json is a conventional ASP.NET Core configuration file containing application settings in JSON format.

appsettings.json is a conventional JSON file for runtime application settings in ASP.NET Core. Templates commonly include logging and allowed-host settings, and you can add configuration for your own application. section 3.4 section 10.2

Organizing custom settings

Group related values under a named object such as MapSettings, then nest values such as DefaultZoomLevel and DefaultLocation.latitude. JSON values may be numbers, but the configuration provider stores them internally as strings. section 10.2

Use appsettings.json to:

  • Define logging and AllowedHosts settings supplied by an ASP.NET Core template. section 10.2
  • Add namespaced, deeply nested key-value pairs for application features. section 10.2
  • Keep environment-specific values in related files such as appsettings.Production.json. section 10.5
  • Avoid storing passwords, API keys, or connection strings in the file. section 10.2
Listing 10.2 Adding configuration values to an appsettings.json file
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "MapSettings": {            #1
    "DefaultZoomLevel": 9,    #2
    "DefaultLocation": {      #3
      "latitude": 50.500,     #3
      "longitude": -4.000     #3
    }
  }
}
#1 Nest all the configuration under the MapSettings key.
#2 Values can be numbers in the JSON file, but they’ll be converted to strings when they’re read.
#3 You can create deeply nested structures to organize your configuration values better.

Use the annotated configuration listing to see how a parent section organizes scalar and nested settings. section 10.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains default and custom nested settings, provider behavior, key casing, and security limits without detailing binding implementation.
Examples
Uses template logging settings, AllowedHosts, MapSettings, DefaultLocation, and appsettings.Production.json.
What it assumes
Assumes a basic ASP.NET Core project and teaches configuration structure from template-generated files.
What you can do after
Operate/configure ASP.NET Core behavior with organized JSON settings and environment-specific files.
How it connects
Connects JSON configuration with configuration providers, IConfiguration, environment-specific configuration, and POCO binding.

Also explained in

Compare how 4 books explain appsettings.json →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.