Utf8JsonWriter
Definition
Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: Utf8JsonWriter.cs
Provides a high-performance API for forward-only, non-cached writing of UTF-8 encoded JSON text.
public sealed class Utf8JsonWriter : IDisposable, IAsyncDisposable
Remarks
It writes the text sequentially with no caching and adheres to the JSON RFC by default (https:// tools.ietf.org/html/rfc8259), with the exception of writing comments. When the user attempts to write invalid JSON and validation is enabled, it throws an InvalidOperationException with a context specific error message. To be able to format the output with indentation and whitespace OR to skip validation, create an instance of JsonWriterOptions and pass that in to the writer.
Inheritance
Object → Utf8JsonWriter
Implements
Constructors
| Constructor | Description |
|---|---|
| Utf8JsonWriter(...) | Constructs a new Utf8JsonWriter instance with a specified bufferWriter. |
Properties
| Property | Type | Description |
|---|---|---|
| BytesCommitted | long |
Returns the amount of bytes committed to the output by the Utf8JsonWriter so far. |
| BytesPending | int |
Returns the amount of bytes written by the Utf8JsonWriter so far that have not yet been flushed to the output and committed. |
| CurrentDepth | int |
Tracks the recursive depth of the nested objects / arrays within the JSON text written so far. This provides the depth of the current token. |
| Options | JsonWriterOptions |
Gets the custom behavior when writing JSON using the Utf8JsonWriter which indicates whether to format the output while writing and whether to skip... |
Methods
| Method | Description |
|---|---|
| Dispose() | Commits any left over JSON text that has not yet been flushed and releases all resources used by the current instance. |
| DisposeAsync() | Asynchronously commits any left over JSON text that has not yet been flushed and releases all resources used by the current instance. |
| 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. |
| Reset | Resets the Utf8JsonWriter internal state so that it can be re-used. |
| WriteBase64String | 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. |
| WriteBase64StringSegment(ReadOnlySpan<byte>, bool) | Writes the input bytes as a partial JSON string. |
| WriteBase64StringValue(ReadOnlySpan<byte>) | Writes the raw bytes value as a Base64 encoded JSON string as an element of a JSON array. |
| WriteBoolean | 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. |
| WriteBooleanValue(bool) | Writes the Boolean value (as a JSON literal "true" or "false") as an element of a JSON array. |
| WriteCommentValue | Writes the string text value (as a JSON comment). |
| WriteEndArray() | Writes the end of a JSON array. |
| WriteEndObject() | Writes the end of a JSON object. |
| WriteNull | Writes the pre-encoded property name 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 | Writes the pre-encoded property name and Decimal value (as a JSON number) as part of a name/value pair of a JSON object. |
| WriteNumberValue | Writes the Decimal value (as a JSON number) as an element of a JSON array. |
| WritePropertyName | Writes the pre-encoded property name (as a JSON string) as the first part of a name/value pair of a JSON object. |
| WriteRawPropertyName(ReadOnlySpan<byte>) | Writes the property name (as a JSON string) as the first part of a name/value pair of a JSON object. The caller guarantees the property name is already properly escaped for the default encoder. |
| WriteRawValue | Writes the input as JSON content. It is expected that the input content is a single complete JSON value. |
| WriteStartArray | Writes the beginning of a JSON array. |
| WriteStartObject | Writes the beginning of a JSON object. |
| WriteString | Writes the pre-encoded property name and DateTime value (as a JSON string) as part of a name/value pair of a JSON object. |
| WriteStringValue | Writes the DateTime value (as a JSON string) as an element of a JSON array. |
| WriteStringValueSegment | Writes the text value segment as a partial JSON string. |
Applies To
| Product | Versions |
|---|---|
| .NET | 9, 10 |
| .NET Standard | 2.0, 2.1 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests.
Open an issue