Skip to content

JsonDocumentBuilder<T>.Parse Method

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll

Overloads

Method Description
Parse(JsonWorkspace, ReadOnlyMemory<byte>, JsonDocumentOptions) Parses UTF-8 encoded JSON directly into a mutable document builder, avoiding the intermediate ParsedJsonDocument allocation and tree walk.
Parse(JsonWorkspace, ReadOnlyMemory<char>, JsonDocumentOptions) Parses text representing a single JSON value directly into a mutable document builder.
Parse(JsonWorkspace, string, JsonDocumentOptions) Parses a string representing a single JSON value directly into a mutable document builder.
Parse(JsonWorkspace, Stream, JsonDocumentOptions) Parses a Stream of UTF-8 encoded data representing a single JSON value directly into a mutable document builder. The Stream will be read...

Parse(JsonWorkspace, ReadOnlyMemory<byte>, JsonDocumentOptions)

Source: JsonDocumentBuilder.Parse.cs

Parses UTF-8 encoded JSON directly into a mutable document builder, avoiding the intermediate ParsedJsonDocument allocation and tree walk.

public static JsonDocumentBuilder<T> Parse(JsonWorkspace workspace, ReadOnlyMemory<byte> utf8Json, JsonDocumentOptions options)

Parameters

Name Type Description
workspace JsonWorkspace The workspace that will own this builder.
utf8Json ReadOnlyMemory<byte> UTF-8 encoded JSON text to parse.
options JsonDocumentOptions Options to control the reader behavior during parsing. (optional)

Returns

JsonDocumentBuilder<T>

A JsonDocumentBuilder representation of the JSON value.

Exceptions

Exception Description
JsonException utf8Json does not represent a valid single JSON value.
ArgumentException options contains unsupported options.

Remarks

Unlike the two-step ParsedJsonDocument.Parse → workspace.CreateBuilder workflow, this method performs a single pass over the input, storing the raw UTF-8 bytes directly as the builder's value backing. MetadataDb rows reference offsets into the raw bytes (the same convention as ParsedJsonDocument), so no per-value copies or DynamicValue headers are needed during parsing. Subsequent mutations append DynamicValue entries after the raw region. The returned builder must be disposed when no longer needed. Because the input is considered to be text, a UTF-8 Byte-Order-Mark (BOM) must not be present.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Parse(JsonWorkspace, ReadOnlyMemory<char>, JsonDocumentOptions)

Source: JsonDocumentBuilder.Parse.cs

Parses text representing a single JSON value directly into a mutable document builder.

public static JsonDocumentBuilder<T> Parse(JsonWorkspace workspace, ReadOnlyMemory<char> json, JsonDocumentOptions options)

Parameters

Name Type Description
workspace JsonWorkspace The workspace that will own this builder.
json ReadOnlyMemory<char> JSON text to parse.
options JsonDocumentOptions Options to control the reader behavior during parsing. (optional)

Returns

JsonDocumentBuilder<T>

A JsonDocumentBuilder representation of the JSON value.

Exceptions

Exception Description
JsonException json does not represent a valid single JSON value.
ArgumentException options contains unsupported options.

Remarks

The text is transcoded from UTF-16 to UTF-8 before parsing. For best performance, prefer the Parse overload if you already have UTF-8 data.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Parse(JsonWorkspace, string, JsonDocumentOptions)

Source: JsonDocumentBuilder.Parse.cs

Parses a string representing a single JSON value directly into a mutable document builder.

public static JsonDocumentBuilder<T> Parse(JsonWorkspace workspace, string json, JsonDocumentOptions options)

Parameters

Name Type Description
workspace JsonWorkspace The workspace that will own this builder.
json string JSON text to parse.
options JsonDocumentOptions Options to control the reader behavior during parsing. (optional)

Returns

JsonDocumentBuilder<T>

A JsonDocumentBuilder representation of the JSON value.

Exceptions

Exception Description
ArgumentNullException json is null.
JsonException json does not represent a valid single JSON value.
ArgumentException options contains unsupported options.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Parse(JsonWorkspace, Stream, JsonDocumentOptions)

Source: JsonDocumentBuilder.Parse.cs

Parses a Stream of UTF-8 encoded data representing a single JSON value directly into a mutable document builder. The Stream will be read to completion.

public static JsonDocumentBuilder<T> Parse(JsonWorkspace workspace, Stream utf8Json, JsonDocumentOptions options)

Parameters

Name Type Description
workspace JsonWorkspace The workspace that will own this builder.
utf8Json Stream UTF-8 encoded JSON data to parse.
options JsonDocumentOptions Options to control the reader behavior during parsing. (optional)

Returns

JsonDocumentBuilder<T>

A JsonDocumentBuilder representation of the JSON value.

Exceptions

Exception Description
ArgumentNullException utf8Json is null.
JsonException utf8Json does not represent a valid single JSON value.
ArgumentException options contains unsupported options.

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