-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Make it easier to get json property values #28588
Comments
cc @bartonjs |
I'm not a fan of it, since it collapses the "undefined/not-present" and "present but The type coercion also seems wrong to me. If what's really wanted is only coercion to string, then maybe that's just |
@bartonjs we already have 15+ occurrences of this in AspNetCore Authentication so we added an extension method for this. We were not going to write The coercion aspect was less common, frequently the values already were strings. |
That's a small number for Ctrl+V (though I admit I'd make a private non-extension utility method for it if it was all in one assembly and it was me). It also doesn't answer the why question. ("Why" is important to understand if it's an API that should be public, and that it has the right name/semantics/etc.) |
(Summarizing things from a couple of different channels) There are a couple of different interpretations of what is lacking (and therefore what to do):
While a caller can't (in C#) define their own conversion operators for the 12 types that are supported, the other solutions are all doable as user defined extensions. Given where we are in the release, that nothing is really blocked functionality-wise, and that this issue is potentially asking for one of 16 solutions (bitvector of 4 interpretations), closing the issue seems most appropriate. If there's strong demand for any specific parts it can always be reconsidered in future versions -- but those are best addressed in specific issues, so they can track through discussion / proposal / API review individually. |
@bartonjs why close? Why not moved to future? |
RE: dotnet/aspnetcore#7105 (comment)
Newtonsoft JObject
.Value<string>(propertyName);
as a convenient way to find a property and extract the value in a single operation. Note this returns null of the property isn't found. It also type converts the various datatypes to strings if that's the T you requested.The equivalent code for JsonDocument looks something like this:
The text was updated successfully, but these errors were encountered: