Skip to content

[Analyzer Proposal]: Recommend using JsonElement.Parse #111957

Open
@stephentoub

Description

@stephentoub

#108930 represents an approved API for .NET 10 that adds JsonElement.Parse methods. Before its existence, developers would write things like:

JsonElement element = JsonDocument.Parse("json").RootElement;

which ends up renting an array from the ArrayPool with the JsonDocument but then never returning it because the JsonDocument isn't disposed.

We should add an analyzer/fixer that flags common patterns folks have used for getting a JsonElement, as called out in #108930, and recommend switching to use the new JsonElement.Parse methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Text.Jsoncode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions