© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•10mo ago•
24 replies
Angius

Issues using `.json5` files for `appsettings.json`

I wanted support for trailing commas and comments in my
appsettings.json
appsettings.json
, so I decided to go with JSON5.
But here's the weird thing.
I can add trailing commas and comments to
appsettings.json
appsettings.json
and everything works perfectly fine. So far so good, but Rider complains that you can't have them in a json file.
No biggie, Rider supports
.json5
.json5
so I renamed the file to
appsettings.json5
appsettings.json5
and changed
Configuration = new ConfigurationBuilder()
    .AddConfiguration(configuration)
    .AddJsonFile("appsettings.json")
Configuration = new ConfigurationBuilder()
    .AddConfiguration(configuration)
    .AddJsonFile("appsettings.json")

to
Configuration = new ConfigurationBuilder()
    .AddConfiguration(configuration)
    .AddEnvironmentVariables("ogma_")
    .AddJsonFile("appsettings.json5")
Configuration = new ConfigurationBuilder()
    .AddConfiguration(configuration)
    .AddEnvironmentVariables("ogma_")
    .AddJsonFile("appsettings.json5")

And... now I'm getting NRE on one of the segments of the config. Everything starts working again as soon as I rename it back to
.json
.json
. I tried to be sneaky and use
.5.json
.5.json
with a file association in Rider, but no cigar, also getting NREs.
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Check if appsettings.json or appsettings.Development.json
C#CC# / help
3y ago
Appsettings.json across projet
C#CC# / help
2y ago
Correct environments handling (appSettings.json)
C#CC# / help
3y ago