<PackageReference Include="System.Text.Json" Version="8.0.0-rc.2.23479.6" />

Utf8JsonWriter

Provides a high-performance API for forward-only, non-cached writing of UTF-8 encoded JSON text.
public long BytesCommitted { get; }

Gets the total number of bytes committed to the output by the current instance so far.

public int BytesPending { get; }

Gets the number of bytes written by the Utf8JsonWriter so far that have not yet been flushed to the output and committed.

public int CurrentDepth { get; }

Gets the depth of the current token.

public JsonWriterOptions Options { get; }

Gets the custom behavior when writing JSON using this instance, which indicates whether to format the output while writing, whether to skip structural JSON validation, and which characters to escape.

public Utf8JsonWriter(IBufferWriter<byte> bufferWriter, JsonWriterOptions options = default)

Initializes a new instance of the Utf8JsonWriter class using the specified IBufferWriter<T> to write the output to and customization options.

public Utf8JsonWriter(Stream utf8Json, JsonWriterOptions options = default)

Initializes a new instance of the Utf8JsonWriter class using the specified stream to write the output to and customization options.

public void Dispose()

Commits any leftover JSON text that has not yet been flushed and releases all resources used by the current instance.

Asynchronously commits any leftover JSON text that has not yet been flushed and releases all resources used by the current instance.

public void Flush()

Commits the JSON text written so far, which makes it visible to the output destination.

public Task FlushAsync(CancellationToken cancellationToken = default)

Asynchronously commits the JSON text written so far, which makes it visible to the output destination.

public void Reset()

Resets the internal state of this instance so that it can be reused.

public void Reset(Stream utf8Json)

Resets the internal state of this instance so that it can be reused with a new instance of Stream.

public void Reset(IBufferWriter<byte> bufferWriter)

Resets the internal state of this instance so that it can be reused with a new instance of IBufferWriter<T>.

public void WriteBase64String(JsonEncodedText propertyName, ReadOnlySpan<byte> bytes)

Writes the pre-encoded property name and raw bytes value (as a Base64 encoded JSON string) as part of a name/value pair of a JSON object.

public void WriteBase64String(string propertyName, ReadOnlySpan<byte> bytes)

Writes the property name and raw bytes value (as a Base64 encoded JSON string) as part of a name/value pair of a JSON object.

public void WriteBase64String(ReadOnlySpan<char> propertyName, ReadOnlySpan<byte> bytes)

Writes the property name and raw bytes value (as a Base64 encoded JSON string) as part of a name/value pair of a JSON object.

public void WriteBase64String(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<byte> bytes)

Writes the property name and raw bytes value (as a Base64 encoded JSON string) as part of a name/value pair of a JSON object.

public void WriteBase64StringValue(ReadOnlySpan<byte> bytes)

Writes the raw bytes value as a Base64 encoded JSON string as an element of a JSON array.

public void WriteBoolean(JsonEncodedText propertyName, bool value)

Writes the pre-encoded property name and Boolean value (as a JSON literal true or false) as part of a name/value pair of a JSON object.

public void WriteBoolean(string propertyName, bool value)

Writes a property name specified as a string and a Boolean value (as a JSON literal true or false) as part of a name/value pair of a JSON object.

public void WriteBoolean(ReadOnlySpan<char> propertyName, bool value)

Writes a property name specified as a read-only character span and a Boolean value (as a JSON literal true or false) as part of a name/value pair of a JSON object.

public void WriteBoolean(ReadOnlySpan<byte> utf8PropertyName, bool value)

Writes a property name specified as a read-only span of bytes and a Boolean value (as a JSON literal true or false) as part of a name/value pair of a JSON object.

public void WriteBooleanValue(bool value)

Writes a Boolean value (as a JSON literal true or false) as an element of a JSON array.

public void WriteCommentValue(string value)

Writes a string text value as a JSON comment.

public void WriteCommentValue(ReadOnlySpan<char> value)

Writes a UTF-16 text value as a JSON comment.

public void WriteCommentValue(ReadOnlySpan<byte> utf8Value)

Writes a UTF-8 text value as a JSON comment.

public void WriteEndArray()

Writes the end of a JSON array.

public void WriteEndObject()

Writes the end of a JSON object.

public void WriteNull(JsonEncodedText propertyName)

Writes the pre-encoded property name and the JSON literal null as part of a name/value pair of a JSON object.

public void WriteNull(string propertyName)

Writes a property name specified as a string and the JSON literal null as part of a name/value pair of a JSON object.

public void WriteNull(ReadOnlySpan<char> propertyName)

Writes a property name specified as a read-only character span and the JSON literal null as part of a name/value pair of a JSON object.

public void WriteNull(ReadOnlySpan<byte> utf8PropertyName)

Writes a property name specified as a read-only span of bytes and the JSON literal null as part of a name/value pair of a JSON object.

public void WriteNullValue()

Writes the JSON literal null as an element of a JSON array.

public void WriteNumber(JsonEncodedText propertyName, decimal value)

Writes the pre-encoded property name and Decimal value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, decimal value)

Writes a property name specified as a string and a Decimal value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, decimal value)

Writes a property name specified as a read-only character span and a Decimal value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, decimal value)

Writes a property name specified as a read-only span of bytes and a Decimal value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, double value)

Writes the pre-encoded property name and Double value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, double value)

Writes a property name specified as a string and a Double value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, double value)

Writes a property name specified as a read-only character span and a Double value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, double value)

Writes a property name specified as a read-only span of bytes and a Double value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, float value)

Writes the pre-encoded property name and Single value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, float value)

Writes a property name specified as a string and a Single value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, float value)

Writes a property name specified as a read-only character span and a Single value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, float value)

Writes a property name specified as a read-only span of bytes and a Single value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, long value)

Writes the pre-encoded property name and Int64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, long value)

Writes a property name specified as a string and an Int64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, long value)

Writes a property name specified as a read-only character span and an Int64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, long value)

Writes a property name specified as a read-only span of bytes and an Int64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, int value)

Writes the pre-encoded property name and Int32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, int value)

Writes a property name specified as a string and an Int32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, int value)

Writes a property name specified as a read-only character span and an Int32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, int value)

Writes a property name specified as a read-only span of bytes and an Int32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, ulong value)

Writes the pre-encoded property name and UInt64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, ulong value)

Writes a property name specified as a string and a UInt64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, ulong value)

Writes a property name specified as a read-only character span and a UInt64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, ulong value)

Writes a property name specified as a read-only span of bytes and a UInt64 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(JsonEncodedText propertyName, uint value)

Writes the pre-encoded property name and UInt32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(string propertyName, uint value)

Writes a property name specified as a string and a UInt32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<char> propertyName, uint value)

Writes a property name specified as a read-only character span and a UInt32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, uint value)

Writes a property name specified as a read-only span of bytes and a UInt32 value (as a JSON number) as part of a name/value pair of a JSON object.

public void WriteNumberValue(decimal value)

Writes a Decimal value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(double value)

Writes a Double value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(float value)

Writes a Single value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(int value)

Writes an Int32 value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(long value)

Writes an Int64 value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(uint value)

Writes a UInt32 value (as a JSON number) as an element of a JSON array.

public void WriteNumberValue(ulong value)

Writes a UInt64 value (as a JSON number) as an element of a JSON array.

public void WritePropertyName(JsonEncodedText propertyName)

Writes the pre-encoded property name (as a JSON string) as the first part of a name/value pair of a JSON object.

public void WritePropertyName(string propertyName)

Writes the property name (as a JSON string) as the first part of a name/value pair of a JSON object.

public void WritePropertyName(ReadOnlySpan<char> propertyName)

Writes the property name (as a JSON string) as the first part of a name/value pair of a JSON object.

public void WritePropertyName(ReadOnlySpan<byte> utf8PropertyName)

Writes the UTF-8 property name (as a JSON string) as the first part of a name/value pair of a JSON object.

public void WriteRawValue(string json, bool skipInputValidation = false)

Writes the input as JSON content. It is expected that the input content is a single complete JSON value.

public void WriteRawValue(ReadOnlySpan<char> json, bool skipInputValidation = false)

Writes the input as JSON content. It is expected that the input content is a single complete JSON value.

public void WriteRawValue(ReadOnlySpan<byte> utf8Json, bool skipInputValidation = false)

Writes the input as JSON content. It is expected that the input content is a single complete JSON value.

public void WriteRawValue(ReadOnlySequence<byte> utf8Json, bool skipInputValidation = false)

Writes the input as JSON content. It is expected that the input content is a single complete JSON value.

public void WriteStartArray()

Writes the beginning of a JSON array.

public void WriteStartArray(JsonEncodedText propertyName)

Writes the beginning of a JSON array with a pre-encoded property name as the key.

public void WriteStartArray(ReadOnlySpan<byte> utf8PropertyName)

Writes the beginning of a JSON array with a property name specified as a read-only span of bytes as the key.

public void WriteStartArray(string propertyName)

Writes the beginning of a JSON array with a property name specified as a string as the key.

public void WriteStartArray(ReadOnlySpan<char> propertyName)

Writes the beginning of a JSON array with a property name specified as a read-only character span as the key.

public void WriteStartObject()

Writes the beginning of a JSON object.

public void WriteStartObject(JsonEncodedText propertyName)

Writes the beginning of a JSON object with a pre-encoded property name as the key.

public void WriteStartObject(ReadOnlySpan<byte> utf8PropertyName)

Writes the beginning of a JSON object with a property name specified as a read-only span of bytes as the key.

public void WriteStartObject(string propertyName)

Writes the beginning of a JSON object with a property name specified as a string as the key.

public void WriteStartObject(ReadOnlySpan<char> propertyName)

Writes the beginning of a JSON object with a property name specified as a read-only character span as the key.

public void WriteString(JsonEncodedText propertyName, DateTime value)

Writes the pre-encoded property name and DateTime value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, DateTime value)

Writes a property name specified as a string and a DateTime value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, DateTime value)

Writes a property name specified as a read-only character span and a DateTime value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, DateTime value)

Writes a UTF-8 property name and a DateTime value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, DateTimeOffset value)

Writes the pre-encoded property name and DateTimeOffset value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, DateTimeOffset value)

Writes a property name specified as a string and a DateTimeOffset value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, DateTimeOffset value)

Writes a property name specified as a read-only character span and a DateTimeOffset value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, DateTimeOffset value)

Writes a UTF-8 property name and a DateTimeOffset value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, Guid value)

Writes the pre-encoded property name and Guid value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, Guid value)

Writes a property name specified as a string and a Guid value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, Guid value)

Writes a property name specified as a read-only character span and a Guid value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, Guid value)

Writes a UTF-8 property name and a Guid value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, JsonEncodedText value)

Writes the pre-encoded property name and pre-encoded value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, JsonEncodedText value)

Writes the property name and pre-encoded value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, string value)

Writes a property name specified as a string and a string text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, ReadOnlySpan<char> value)

Writes a UTF-16 property name and UTF-16 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<byte> utf8Value)

Writes a UTF-8 property name and UTF-8 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, string value)

Writes the pre-encoded property name and string text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, ReadOnlySpan<char> value)

Writes the pre-encoded property name and text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, ReadOnlySpan<char> value)

Writes a property name specified as a string and a UTF-16 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, ReadOnlySpan<char> value)

Writes a UTF-8 property name and UTF-16 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(JsonEncodedText propertyName, ReadOnlySpan<byte> utf8Value)

Writes the pre-encoded property name and UTF-8 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(string propertyName, ReadOnlySpan<byte> utf8Value)

Writes a property name specified as a string and a UTF-8 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, ReadOnlySpan<byte> utf8Value)

Writes a UTF-16 property name and UTF-8 text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, JsonEncodedText value)

Writes the property name and pre-encoded value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<char> propertyName, string value)

Writes a UTF-16 property name and string text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, JsonEncodedText value)

Writes the UTF-8 property name and pre-encoded value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteString(ReadOnlySpan<byte> utf8PropertyName, string value)

Writes a UTF-8 property name and string text value (as a JSON string) as part of a name/value pair of a JSON object.

public void WriteStringValue(DateTime value)

Writes a DateTime value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(DateTimeOffset value)

Writes a DateTimeOffset value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(Guid value)

Writes a Guid value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(JsonEncodedText value)

Writes the pre-encoded text value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(string value)

Writes a string text value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(ReadOnlySpan<char> value)

Writes a UTF-16 text value (as a JSON string) as an element of a JSON array.

public void WriteStringValue(ReadOnlySpan<byte> utf8Value)

Writes a UTF-8 text value (as a JSON string) as an element of a JSON array.