A JSON file provider loads application settings from JSON-formatted files into ASP.NET Core configuration. WebApplicationBuilder adds appsettings.json and the environment-specific appsettings.ENVIRONMENT.json automatically, so most applications can use these defaults without extra setup. section 10.2.1
You can add a provider explicitly with AddJsonFile(). The optional setting determines whether a missing file is ignored or causes a FileNotFoundException. Providers contribute key-value pairs to IConfiguration, and later providers replace earlier values when keys overlap. section 10.2.1 section 10.2.2
Load and reload appsettings.json
WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Configuration.Sources.Clear(); builder.Configuration.AddJsonFile( "appsettings.json", optional: true, reloadOnChange: true); WebApplication app = builder.Build(); app.MapGet("/", () => app.Configuration.AsEnumerable()); app.Run(); This example starts with no default providers, adds an optional JSON file, and rebuilds IConfiguration when the file changes. The application can then inspect the resulting settings through IConfiguration. section 10.2.1 section 10.2.4
Use JSON providers to:
- Keep shared settings in one JSON file and application settings in another. section 10.2.2
- Place environment variables after JSON providers so sensitive or deployment-specific values override file settings. section 10.2.2
- Change settings such as logging levels while the application is running, when file reloading is enabled. section 10.2.4
Listing 10.3 Loading appsettings.json by clearing the configuration sources
WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Configuration.Sources.Clear(); #1 builder.Configuration.AddJsonFile("appsettings.json", optional: true); #2 WebApplication app = builder.Build(); app.MapGet("/", () => app.Configuration.AsEnumerable()); #3 app.Run(); #1 Clears the providers configured by default in WebApplicationBuilder #2 Adds a JSON configuration provider, providing the name of the configuration file #3 Returns all the configuration key-value pairs for display purposes
Use the annotated listing to see the complete provider replacement flow: clear the defaults, add appsettings.json, and expose the resulting configuration. section 10.2.1

