Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OOTB support for appsettings using JSON5 #59752

Open
1 task done
mu88 opened this issue Jan 7, 2025 · 3 comments
Open
1 task done

Add OOTB support for appsettings using JSON5 #59752

mu88 opened this issue Jan 7, 2025 · 3 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@mu88
Copy link

mu88 commented Jan 7, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

It's not uncommon that one wants to add comments to appsettings*.json. Even the official ASP.NET Core docs contain such examples (see here):

{
  // This file is not imported as a snippet so can be changed for testing.
  ...left out for brevity

But since the official JSON standard does not allow to use comments, this leads to schema validation errors in IDEs like JetBrains Rider:
Image

Describe the solution you'd like

JSON5 is a well-adopted standard that extends JSON with comments. In contrast to JSONC, there is a proper specification (see here). But when renaming appsettings.json to appsettings.json5, neither a .NET CLI nor ASP.NET Core app picks up this config file anymore.
Of course, one could manually add them via config.AddJsonFile("appsettings.json5"); - but then you also have to add config.AddJsonFile($"appsettings.{env.EnvironmentName}.json5") for the environment-specific stuff.

Since JSON5 seems like a mature standard to me, I suggest adding OOTB support for appsettings*.json5. So far, I found the following spots:

ASP.NET Core

Sources

Current

        configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: reloadOnChange)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: reloadOnChange);

New

        configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: reloadOnChange)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: reloadOnChange)
            .AddJsonFile($"appsettings.json5", optional: true, reloadOnChange: reloadOnChange)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json5", optional: true, reloadOnChange: reloadOnChange);

.NET runtime

Sources

Current

            appConfigBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: reloadOnChange)
                    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: reloadOnChange);

New

            appConfigBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: reloadOnChange)
                    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: reloadOnChange)
                    .AddJsonFile($"appsettings.json5", optional: true, reloadOnChange: reloadOnChange)
                    .AddJsonFile($"appsettings.{env.EnvironmentName}.json5", optional: true, reloadOnChange: reloadOnChange);

Additional context

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jan 7, 2025
@martincostello
Copy link
Member

Looks like this issue should be transferred to dotnet/runtime as that's where the configuration providers are defined.

@mu88
Copy link
Author

mu88 commented Jan 7, 2025

@martincostello: is this something that I can easily do?

@martincostello
Copy link
Member

Either close this issue and open a new one there, or wait until a member of the ASP.NET Core team that has the appropriate permissions transfers this issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

2 participants