Skip to content

Add a JsonObject.TryAdd method. #110244

@eiriktsarpalis

Description

@eiriktsarpalis

This workaround requires dual lookup if the key is missing, which suggests to me that a JsonObject.TryAddmethod similar to the one in #107947 might be necessary.

Originally posted by @eiriktsarpalis in dotnet/aspire#6312 (comment)

API Proposal

Exposing the APIs as approved for OrderedDictionary to JsonObject:

namespace System.Text.Json.Nodes;

public partial class JsonObject
{
    public bool TryAdd(string propertyName, JsonNode? value, out int index);
    public bool TryGetPropertyValue(string propertyName, out JsonNode? jsonNode, out int index);
}

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Text.Jsonin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions