Skip to content

Add JsonElement.GetPropertyCount() #104692

@eiriktsarpalis

Description

@eiriktsarpalis

API Proposal

Even though JsonElement exposes API for getting the length of a given array, there is no equivalent functionality for objects:

namespace System.Text.Json;

public partial struct JsonElement
{
     public int GetArrayLength();
+    public int GetPropertyCount();
}

API Usage

JsonElement element = JsonSerializer.Deserialize<JsonElement>("""{ "foo" : 1, "bar" : 2 }""");
Console.WriteLine(element.GetPropertyCount()); // 2

/cc @bartonjs

Metadata

Metadata

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Text.Jsonhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions