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:
- The raw value should always be a valid JSON value, therefore strings/properties must always include quotes.
- Composite values preserve whitespace and comments contained in the original JSON document.