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



