Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 23, 2025

Summary

Investigation into reported issue #83766 regarding JsonObject constructor with PropertyNameCaseInsensitive option.

Investigation Results

After thorough investigation:

  1. The reported issue is already fixed: The PropertyNameCaseInsensitive functionality works correctly with the JsonObject constructor that takes IEnumerable<KeyValuePair<string, JsonNode?>> and JsonNodeOptions. Case-insensitive lookups function as expected.

  2. Test coverage exists: The existing test TestJsonNodeOptionsSet already validates this scenario:

    • Creates a JsonObject with PropertyNameCaseInsensitive = true
    • Uses the constructor with properties: new JsonObject(props, options)
    • Verifies case-insensitive lookup works: Assert.Equal("World", (string)jObject["hello"])
  3. No bug was present: Testing confirmed that using the options parameter vs the Options property makes no behavioral difference in the constructor context, as the Options property simply returns the _options field set by the base JsonNode(options) constructor.

Conclusion

The issue can be closed as the functionality works correctly and has adequate test coverage. No code changes are needed.

Related to #83766

Original prompt

This section details on the original issue you should resolve

<issue_title>JsonObject constructor incorrect options behavior for JsonNodeOptions: PropertyNameCaseInsensitive</issue_title>
<issue_description>### Description

Using JsonObject contructor with JsonNodeOptions: PropertyNameCaseInsensitive = true results in incorrect options behavior.

Reproduction Steps

Run following code snippet and note the value of variable "iAmNull"

var jsonObject = new JsonObject(new List<KeyValuePair<string, JsonNode?>> { new("key", "value") }, new JsonNodeOptions {PropertyNameCaseInsensitive = true} );
var iAmNull = jsonObject["kEy"];

Expected behavior

iAmNull should be 'value'

Actual behavior

iAmNull is 'null'

Regression?

No response

Known Workarounds

Use a different constructor. See code snippet:

var jsonNodeOptions = new JsonNodeOptions { PropertyNameCaseInsensitive = true };
var jsonObject = new JsonObject(jsonNodeOptions) { new("key", "value") };

var iAmNotNull= jsonObject["kEy"];

Configuration

  • Which version of .NET is the code running on? .NET 6
  • What OS and version, and what distro if applicable? Windows 10 22H2
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? Do you know whether it is specific to that configuration? No

Other information

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.
Issue Details

Description

Using JsonObject contructor with JsonNodeOptions: PropertyNameCaseInsensitive = true results in incorrect options behavior.

Reproduction Steps

Run following code snippet and note the value of variable "iAmNull"

var jsonObject = new JsonObject(new List<KeyValuePair<string, JsonNode?>> { new("key", "value") }, new JsonNodeOptions {PropertyNameCaseInsensitive = true} );
var iAmNull = jsonObject["kEy"];

Expected behavior

iAmNull should be = "value"

Actual behavior

iAmNull should NOT = null

Regression?

No response

Known Workarounds

Use a different constructor. See code snippet:

var jsonNodeOptions = new JsonNodeOptions { PropertyNameCaseInsensitive = true };
var jsonObject = new JsonObject(jsonNodeOptions) { new("key", "value") };

var iAmNotNull= jsonObject["kEy"];

Configuration

  • Which version of .NET is the code running on? .NET 6
  • What OS and version, and what distro if applicable? Windows 10 22H2
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? Do you know whether it is specific to that configuration? No

Other information

No response

Author: astrberg
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

Fixes #83766


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix incorrect options behavior in JsonObject constructor Fix JsonObject constructor to use Options property for consistency Oct 23, 2025
Copilot AI requested a review from stephentoub October 23, 2025 19:44
Copilot finished work on behalf of stephentoub October 23, 2025 19:44
@stephentoub
Copy link
Member

@copilot, it doesn't seem like using options vs Options should result in a behavioral difference; won't the Options property just return that same instance in this case? In fact, is the originally cited issue still actually an issue, or was the problem already fixed?

Copy link
Contributor Author

Copilot AI commented Oct 23, 2025

@copilot, it doesn't seem like using options vs Options should result in a behavioral difference; won't the Options property just return that same instance in this case? In fact, is the original...

You're absolutely right. I investigated and confirmed that using options vs Options makes no behavioral difference in this context.

During construction, the Options property simply returns the _options field that was set by the base constructor JsonNode(options), so both refer to the same instance. The existing tests (including TestJsonNodeOptionsSet) already pass with the original code.

The change doesn't fix any actual bug - it was based on a misunderstanding of the code flow. The original issue description was incomplete, making it difficult to identify a concrete reproduction case. Should I revert this change?

Copilot finished work on behalf of stephentoub October 23, 2025 21:49
@stephentoub
Copy link
Member

Should I revert this change?

Yes, and then please confirm that the problem cited in the original issue is fixed and that there's a test case covering it. If it's fixed and there's a test case, we can close both the issue and this PR. If it's fixed but there's no test case, please add one. If it's not fixed, please fix it.

@stephentoub
Copy link
Member

@copilot

Copy link
Contributor Author

Copilot AI commented Oct 23, 2025

Should I revert this change?

Yes, and then please confirm that the problem cited in the original issue is fixed and that there's a test case covering it. If it's fixed and there's a test case, ...

Changes reverted in commit 4154eef.

Investigation findings:

  • ✅ The original issue is already fixed - PropertyNameCaseInsensitive works correctly with the JsonObject constructor
  • ✅ Test coverage already exists via TestJsonNodeOptionsSet which validates the constructor with IEnumerable<KeyValuePair> and case-insensitive options
  • Confirmed the test passes: case-insensitive lookups work as expected (e.g., jObject["hello"] correctly returns "World" when the key is "Hello")

The issue and PR can be closed.

Copilot AI changed the title Fix JsonObject constructor to use Options property for consistency Investigation: JsonObject PropertyNameCaseInsensitive - Issue Already Fixed Oct 23, 2025
Copilot finished work on behalf of stephentoub October 23, 2025 22:13
@jkotas jkotas deleted the copilot/fix-jsonobject-options-issue branch October 24, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonObject constructor incorrect options behavior for JsonNodeOptions: PropertyNameCaseInsensitive

3 participants