-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add JsonElement.Parse #116363
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.Parse #116363
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
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.
Pull Request Overview
This PR introduces new JsonElement.Parse overloads for directly parsing JSON into a JsonElement, replaces existing JsonDocument.Parse(...).RootElement usage with the new API, updates tests to exercise and validate these overloads, and adds XML documentation for the new methods.
- Added
JsonElement.Parseoverloads acceptingstring,ReadOnlySpan<char>, andReadOnlySpan<byte>with optionalJsonDocumentOptions - Refactored library and test code to use
JsonElement.Parsein place ofJsonDocument.Parse(...).RootElement - Updated XML docs and added tests covering valid, invalid, and option-respecting parse scenarios
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
JsonElement.Parse.cs |
Added public Parse overloads and XML documentation |
JsonDocument.Parse.cs |
Switched internal APIs to use ReadOnlySpan<char> instead of ReadOnlyMemory<char> |
JsonNode.Parse.cs |
Changed calls from ParseValue to new Parse overloads |
JsonSerializer.Write.Element.cs |
Updated serialization helpers to use JsonElement.Parse |
Tests under System.Text.Json.Tests |
Refactored tests to use JsonElement.Parse, added new tests for valid/invalid parsing and options |
|
@stephentoub could you describe a summary of the memory implications for these methods, please? If there's no I saw the |
src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.Parse.cs
Show resolved
Hide resolved
It's the same as if you did |
src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.Parse.cs
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.
Thanks
Closes #108930