-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 JsonElement.GetPropertyCount()
#106222
Conversation
Note regarding the
|
1 similar comment
Note regarding the
|
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDocumentTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Can I mark this ready for review or do you still have changes you want to make?
@eiriktsarpalis I still have some issues with the result of |
Oh, interesting. This suggests that there might be an issue with the value of the runtime/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs Lines 143 to 152 in bcca12c
It might be worth investigating what the value represents in objects and see if there's an easy way to obtain the actual property count from it. |
6a9c09a
to
9ec53b5
Compare
…/runtime into json-get-property-count
int propertyCount = 0; | ||
int objectOffset = index + DbRow.Size; | ||
int innerDepth = 0; | ||
for (; objectOffset < _parsedData.Length; objectOffset += DbRow.Size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with this approach is that needs to perform a traversal of the entire object to compute the size. This is already possible with EnumerateObject()
, we should only include this API if we can guarantee that it's constant-time.
Were you able to determine what the row.SizeOrLength
value represents in the case of objects and if so, can be meaningfully used (or changed) so that we can obtain the property count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some test cases failed when I tried to update the SizeOrLength
for object properties count, so I tried this way.
Would try to update the SizeOrLength
to do some research on the failed cases, thanks for the input
closed in favor of #106503 |
fixes #104692