question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate keys in JSON configuration

See original GitHub issue

When 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:

  1. Using version ‘2.2.0’ of package ‘Microsoft.Extensions.Configuration.Json’
  2. Create a configuration file with contents:
{
    "my-duplicate-key": true,
    "my-duplicate-key": false
}
  1. Run this code ConfigurationBuilder.AddJsonFile
  2. 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gfoidlcommented, Sep 24, 2019

Expected behavior

…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.

0reactions
msftbot[bot]commented, Jun 4, 2020

Paging @dotnet/extensions-migration ! This issue has been revived from staleness. Please take a look and route to the appropriate repository.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found