Duplicate keys in JSON configuration
See original GitHub issueWhen using ConfigurationBuilder.AddJsonFile
to load settings from a config.json
file, there is no exception when the content of the file contains a duplicate key.
To Reproduce
Steps to reproduce the behavior:
- Using version ‘2.2.0’ of package ‘Microsoft.Extensions.Configuration.Json’
- Create a configuration file with contents:
{
"my-duplicate-key": true,
"my-duplicate-key": false
}
- Run this code
ConfigurationBuilder.AddJsonFile
- An exception is expected, but the code continues without exception
Expected behavior
An exception should be thrown that there is a duplicate key “my-duplicate-key” in the configuration file.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Does JSON syntax allow duplicate keys in an object?
The short answer: Yes but is not recommended. The long answer: It depends on what you call valid... ECMA-404 "The JSON Data Interchange ......
Read more >How do you handle duplicate keys in JSON?
Here, the valid duplicate keys in JSON is an exception and not a rule,but here we'll face the common problem when it comes...
Read more >Duplicate Keys in JSON Objects
We can have duplicate keys in a JSON object, and it would still be valid.
Read more >How can I detect duplicate keys in JSON request body?
Detecting duplicate keys requires parsing the JSON object in a streaming fashion. The builtin JSON.parse() doesn't do that.
Read more >Parse policy- Duplicate Key in JSON Request | API Connect
We have an API configured with Parse and Validate policy. As part of testing an error case, We are getting JSON request with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…or the behavior remains as is, but is documented – right now there is no info in the docs what happens if duplicate keys are present.
Paging @dotnet/extensions-migration ! This issue has been revived from staleness. Please take a look and route to the appropriate repository.