Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReadOnlySpan<byte> api to JsonElement.EnumerateObject() #30207

Closed
ghord opened this issue Jul 10, 2019 · 3 comments
Closed

Add ReadOnlySpan<byte> api to JsonElement.EnumerateObject() #30207

ghord opened this issue Jul 10, 2019 · 3 comments

Comments

@ghord
Copy link

ghord commented Jul 10, 2019

Currently it is not possible to enumerate property names from JsonElement as raw spans.

There are api's that let you get property once you know the name such as JsonElement.TryGetProperty(ReadOnlySpan<byte>, out JsonElement), but the result of object enumeration - JsonProperty has only one string property Name.

Using JsonProperty.Name converts utf8 data and allocates in getter. It should be possible to get property name as a raw ReadOnlySpan<byte>.

@ghord
Copy link
Author

ghord commented Jul 10, 2019

It is also not possible to get raw string value as ReadOnlySpan<byte> from JsonElement that is a string. GetRawText() doesn't help - it returns string.

@ericstj
Copy link
Member

ericstj commented Jul 10, 2019

@ahsonkhan / @steveharter / @bartonjs if they know of a way to do this using current API. If using the reader I imagine you could get at ValueSequence/ValueSpan when reading a JsonTokenType.PropertyName. I don't see a great way get at the raw property Spans when using JsonElement.

@bartonjs
Copy link
Member

JsonElement is intentionally hiding the encoding in this release so we don't box ourselves out of supporting a UTF-16 (string) based reader in the future.

If you're wanting an equality check, we have that with JsonProperty.NameEquals (or a value check is JsonElement.ValueEquals). Anything more than that requires transcoding to System.String.

Duplicate of #30046.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants