Skip to content

Add JsonElement.ValueSpan #77666

@krwq

Description

@krwq

Updated API Proposal

Following conversation with @annelo-msft we identified the key use case is offering a non-allocating variant of the JsonElement.GetRawText method. As such we should probably go ahead with the JsonMarshal design:

namespace System.Runtime.InteropServices;

public partial class JsonMarshal
{
    public static bool TryGetRawValue(JsonElement element, out ReadOnlySpan<byte> rawValue);
}

Furthermore:

  1. The raw value should always be a valid JSON value, therefore strings/properties must always include quotes.
  2. Composite values preserve whitespace and comments contained in the original JSON document.

Metadata

Metadata

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 mergedpartner-impactThis issue impacts a partner who needs to be kept updated

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions