Open vllama opened 1 year ago
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Author: | vllama |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Text.Json`, `untriaged` |
Milestone: | - |
There are currently the TryGetPropertyValue()
and ContainsKey()
properties that can help. I've used these extensively in my json-everything
libraries.
I'll leave this to the dotnet team to confirm, but I believe there are some optimizations they've implemented (e.g. partial object parsing), and they want to encourage people to use these methods over things like the Keys
property (which would require parsing the entire object).
@gregsdennis : thanks for that. I am currently using those as well, but since JsonObject Implements IDictionary, I don't believe enumerating keys would be a performance impact, especially since the use case for enumerating keys is most likely a very flat json structure.
Background and motivation
Currently to get the Keys of a JsonObject is has to be cast to one of the dictionaries it explicitly implements like
(IDictionary<string, JsonNode>)jsonObject).Keys
We are using JsonObject becasue we have to manipulate json quite a bit, and enumerating the keys helps a lot.
API Usage
Alternative Designs
Extension Method: