-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[API Proposal]: Add JsonElement.ValueEquals(JsonElement) #99994
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
I have this as an extension in Json.More.Net. var isEqual = elt1.IsEquivalentTo(elt2); The code is here if you want to inspect. |
Thanks @gregsdennis! Your implementation still allocates though if the two Also, comparing two |
This is true regardless of what .Net numeric type you use. It's an inherent consequence of a limited practical numeric space vs JSON's unlimited theoretical numeric space. I chose |
Yes, but I would imagine a |
Yeah, that doesn't work, either: #97490.
|
But isn't that the current behavior of I would therefore propose that |
Duplicate of #33388. Note that this has already been implemented in .NET 8 for |
@eiriktsarpalis I think the ability to do this without allocation on |
Background and motivation
The
System.Text.Json.JsonElement
struct currently providesValueEquals
overloads for comparing the value of aJsonElement
with a string (string
,ReadOnlySpan<char>
orReadOnlySpan<byte>
) representation of anotherJsonElement
instance. However, if we want to compare twoJsonElement
instances, then this requires the following, which requires heap allocations and UTF-8 decoding.It would be presumably much more efficient to be able to do:
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: