Utf8JsonWriter Class

Definition

Provides a high-performance API for forward-only, non-cached writing of UTF-8 encoded JSON text.

public ref class Utf8JsonWriter sealed : IAsyncDisposable, IDisposable
public sealed class Utf8JsonWriter : IAsyncDisposable, IDisposable
type Utf8JsonWriter = class
    interface IAsyncDisposable
    interface IDisposable
Public NotInheritable Class Utf8JsonWriter
Implements IAsyncDisposable, IDisposable
Inheritance
Utf8JsonWriter
Implements

Remarks

Utf8JsonWriter writes the text sequentially with no caching and by default adheres to the JSON RFC, with the exception of writing comments.

A method that attempts to write invalid JSON when validation is enabled throws an InvalidOperationException with a context-specific error message.

To be able to format the output with indentation and white space, to skip validation, OR to customize the escaping behavior, create an instance of JsonWriterOptions and pass it in to the writer.

Constructors

Utf8JsonWriter(IBufferWriter<Byte>, JsonWriterOptions)

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

Utf8JsonWriter(Stream, JsonWriterOptions)

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

Properties

BytesCommitted

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

BytesPending

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

CurrentDepth

Gets the depth of the current token.

Options

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.

Methods

Dispose()

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

DisposeAsync()

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Flush()

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

FlushAsync(CancellationToken)

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

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Reset()

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

Reset(IBufferWriter<Byte>)

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

Reset(Stream)

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

ToString()

Returns a string that represents the current object.

(Inherited from Object)
WriteBase64String(JsonEncodedText, ReadOnlySpan<Byte>)

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.

WriteBase64String(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)

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.

WriteBase64String(ReadOnlySpan<Char>, ReadOnlySpan<Byte>)

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.

WriteBase64String(String, ReadOnlySpan<Byte>)

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.

WriteBase64StringValue(ReadOnlySpan<Byte>)

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

WriteBoolean(JsonEncodedText, Boolean)

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.

WriteBoolean(ReadOnlySpan<Byte>, Boolean)

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.

WriteBoolean(ReadOnlySpan<Char>, Boolean)

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.

WriteBoolean(String, Boolean)

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.

WriteBooleanValue(Boolean)

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

WriteCommentValue(ReadOnlySpan<Byte>)

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

WriteCommentValue(ReadOnlySpan<Char>)

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

WriteCommentValue(String)

Writes a string text value as a JSON comment.

WriteEndArray()

Writes the end of a JSON array.

WriteEndObject()

Writes the end of a JSON object.

WriteNull(JsonEncodedText)

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

WriteNull(ReadOnlySpan<Byte>)

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.

WriteNull(ReadOnlySpan<Char>)

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.

WriteNull(String)

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

WriteNullValue()

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

WriteNumber(JsonEncodedText, Decimal)

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

WriteNumber(JsonEncodedText, Double)

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

WriteNumber(JsonEncodedText, Int32)

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

WriteNumber(JsonEncodedText, Int64)

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

WriteNumber(JsonEncodedText, Single)

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

WriteNumber(JsonEncodedText, UInt32)

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

WriteNumber(JsonEncodedText, UInt64)

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

WriteNumber(ReadOnlySpan<Byte>, Decimal)

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.

WriteNumber(ReadOnlySpan<Byte>, Double)

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.

WriteNumber(ReadOnlySpan<Byte>, Int32)

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.

WriteNumber(ReadOnlySpan<Byte>, Int64)

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.

WriteNumber(ReadOnlySpan<Byte>, Single)

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.

WriteNumber(ReadOnlySpan<Byte>, UInt32)

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.

WriteNumber(ReadOnlySpan<Byte>, UInt64)

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.

WriteNumber(ReadOnlySpan<Char>, Decimal)

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.

WriteNumber(ReadOnlySpan<Char>, Double)

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.

WriteNumber(ReadOnlySpan<Char>, Int32)

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.

WriteNumber(ReadOnlySpan<Char>, Int64)

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.

WriteNumber(ReadOnlySpan<Char>, Single)

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.

WriteNumber(ReadOnlySpan<Char>, UInt32)

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.

WriteNumber(ReadOnlySpan<Char>, UInt64)

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.

WriteNumber(String, Decimal)

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.

WriteNumber(String, Double)

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.

WriteNumber(String, Int32)

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.

WriteNumber(String, Int64)

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.

WriteNumber(String, Single)

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.

WriteNumber(String, UInt32)

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.

WriteNumber(String, UInt64)

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.

WriteNumberValue(Decimal)

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

WriteNumberValue(Double)

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

WriteNumberValue(Int32)

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

WriteNumberValue(Int64)

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

WriteNumberValue(Single)

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

WriteNumberValue(UInt32)

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

WriteNumberValue(UInt64)

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

WritePropertyName(JsonEncodedText)

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

WritePropertyName(ReadOnlySpan<Byte>)

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

WritePropertyName(ReadOnlySpan<Char>)

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

WritePropertyName(String)

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

WriteStartArray()

Writes the beginning of a JSON array.

WriteStartArray(JsonEncodedText)

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

WriteStartArray(ReadOnlySpan<Byte>)

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

WriteStartArray(ReadOnlySpan<Char>)

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

WriteStartArray(String)

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

WriteStartObject()

Writes the beginning of a JSON object.

WriteStartObject(JsonEncodedText)

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

WriteStartObject(ReadOnlySpan<Byte>)

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

WriteStartObject(ReadOnlySpan<Char>)

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

WriteStartObject(String)

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

WriteString(JsonEncodedText, DateTime)

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

WriteString(JsonEncodedText, DateTimeOffset)

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

WriteString(JsonEncodedText, Guid)

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

WriteString(JsonEncodedText, JsonEncodedText)

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.

WriteString(JsonEncodedText, ReadOnlySpan<Byte>)

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.

WriteString(JsonEncodedText, ReadOnlySpan<Char>)

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

WriteString(JsonEncodedText, String)

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.

WriteString(ReadOnlySpan<Byte>, DateTime)

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.

WriteString(ReadOnlySpan<Byte>, DateTimeOffset)

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.

WriteString(ReadOnlySpan<Byte>, Guid)

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.

WriteString(ReadOnlySpan<Byte>, JsonEncodedText)

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.

WriteString(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)

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.

WriteString(ReadOnlySpan<Byte>, ReadOnlySpan<Char>)

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.

WriteString(ReadOnlySpan<Byte>, String)

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.

WriteString(ReadOnlySpan<Char>, DateTime)

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.

WriteString(ReadOnlySpan<Char>, DateTimeOffset)

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.

WriteString(ReadOnlySpan<Char>, Guid)

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.

WriteString(ReadOnlySpan<Char>, JsonEncodedText)

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

WriteString(ReadOnlySpan<Char>, ReadOnlySpan<Byte>)

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.

WriteString(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

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.

WriteString(ReadOnlySpan<Char>, String)

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.

WriteString(String, DateTime)

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.

WriteString(String, DateTimeOffset)

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.

WriteString(String, Guid)

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.

WriteString(String, JsonEncodedText)

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

WriteString(String, ReadOnlySpan<Byte>)

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.

WriteString(String, ReadOnlySpan<Char>)

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.

WriteString(String, String)

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.

WriteStringValue(DateTime)

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

WriteStringValue(DateTimeOffset)

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

WriteStringValue(Guid)

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

WriteStringValue(JsonEncodedText)

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

WriteStringValue(ReadOnlySpan<Byte>)

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

WriteStringValue(ReadOnlySpan<Char>)

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

WriteStringValue(String)

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

Extension Methods

ConfigureAwait(IAsyncDisposable, Boolean)

Configures how awaits on the tasks returned from an async disposable are performed.

Applies to