[release/10.0] Fixing JsonPatchDocument bug #65736
Merged
wtgodbe merged 10 commits intorelease/10.0from Mar 11, 2026
Merged
Conversation
When a JsonArray was passed as the target parameter, it was being cast to IList, resulting in null. This happened because JsonArray only properly implements IList<JsonNode>, not the non-generic IList interface. The fix adds a conditional check: if the object is IList<JsonNode> (like JsonArray), handle it properly instead of returning null. So now method returns actual array value rather than null. All types that implements IList are handled as before. Types that implement IList<JsonNode> now correctly return the array value
When a JsonArray was passed as the target parameter, it was being cast to IList, resulting in null. This happened because JsonArray only properly implements IList<JsonNode>, not the non-generic IList interface. The fix adds a conditional check: if the object is IList<JsonNode> (like JsonArray), handle it properly instead of returning null. So now method returns actual array value rather than null. All types that implements IList are handled as before. Types that implement IList<JsonNode> now correctly return the array value
adityamandaleeka
approved these changes
Mar 11, 2026
Member
|
Approved over email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #65470 to release/10.0
/cc @adityamandaleeka @HPOD00019
Fixing JsonPatchDocument bug with nested array property traversal
Fix JsonPatch operations on nested array element properties
Description
ListAdapter.TryTraversecasts the target to non-genericIList, butJsonArrayonly implements genericIList<JsonNode>. This causes all JSON Patch operations that traverse into array elements (e.g.,/items/0/name) to fail with "target location not found" when applied toJsonNode/JsonObjecttargets. The fix alignsTryTraversewith the pattern already used by every other method in the class (TryAdd,TryGet,TryRemove,TryReplace,TryTest), usingTryGetListTypeArgumentandGenericListOrJsonArrayUtilities.Fixes #65409
Customer Impact
Customer reported. JSON Patch operations cannot replace, add, remove, or access properties within array elements when applied to
JsonNode/JsonObjectinstances. For example, a path like/items/0/namethrows aJsonPatchExceptioneven though the path is valid per RFC 6902. There is no workaround. The customer is actively waiting for this fix in 10.0 servicing.Regression?
This has been present since
Microsoft.AspNetCore.JsonPatch.SystemTextJsonshipped in 10.0.Risk
5 src lines changed in a single method (
TryTraverse) to use the same utility methods already called by every other method in the same class. 155 test lines added across 8 new tests.Verification
Packaging changes reviewed?
When servicing release/2.3