-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: Add async parse overload for JsonNode
#88248
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
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackground and motivationBoth I won't write a paragraph about why API ProposalBasically copy of existing namespace System.Text.Json;
public class JsonNode
{
public static Task<JsonNode?> ParseAsync(
Stream utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = default,
CancellationToken cancellationToken = default);
} API UsageNothing revolutional really... using System.IO;
using System.Text.Json.Nodes;
using var stream = File.OpenRead("myFile.json");
var node = await JsonNode.ParseAsync(stream);
... Alternative DesignsNo response RisksNo response
|
Seems reasonable, I think we could easily implement this method using existing internal methods. TL;DR we could just compose the existing Slightly related, we could also consider adding async serialization support for the |
Looks good as proposed namespace System.Text.Json;
public class JsonNode
{
public static Task<JsonNode?> ParseAsync(
Stream utf8Json,
JsonNodeOptions? nodeOptions = null,
JsonDocumentOptions documentOptions = default,
CancellationToken cancellationToken = default);
} |
JsonNode
and JsonElement
JsonNode
JsonNode
JsonNode
Background and motivation
Both
JsonSerializer
andJsonDocument
have async parse method overloads when deserializing fromStream
. However,JsonNode
andJsonElement
do not. This is especially odd sinceJsonNode.Parse
under the hood callsJsonElement.ParseElement
which under the hood usesJsonDocument
which already has necessary asyn overloads.I won't write a paragraph about why
async
is preferred when using IO operations.API Proposal
Basically copy of existing
Stream
-related signature, but withAsync
suffix in name, warpped return type intoTask
and additional optionalCancellationToken
parameter:API Usage
Nothing revolutional really...
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: