Table of Contents

Struct JsonReader

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

Reads JSON values from a UTF-8 byte buffer.

public ref struct JsonReader
Inherited Members

Constructors

JsonReader(ReadOnlySpan<byte>, bool, JsonCommentHandling)

Initializes a new instance of the JsonReader struct.

public JsonReader(ReadOnlySpan<byte> jsonUtf8, bool allowTrailingCommas = false, JsonCommentHandling commentHandling = JsonCommentHandling.Disallow)

Parameters

jsonUtf8 ReadOnlySpan<byte>

The UTF-8 JSON bytes to read from.

allowTrailingCommas bool

A value indicating whether trailing commas should be accepted while reading arrays and objects.

commentHandling JsonCommentHandling

The policy for handling comments during deserialization.

Methods

CreatePeekReader()

Creates an independent copy of this reader at the current position.

public readonly JsonReader CreatePeekReader()

Returns

JsonReader

A copy of this reader positioned at the same location.

Remarks

Advancing the returned reader does not affect this instance.

EnsureFullyConsumed()

Verifies that the entire input has been consumed except for insignificant whitespace.

public void EnsureFullyConsumed()

ReadBase64Bytes()

Reads a base64-encoded JSON string value that may be null.

public byte[]? ReadBase64Bytes()

Returns

byte[]

The decoded bytes, or null when the next token is a JSON null literal.

ReadBoolean()

Reads a required JSON boolean literal.

public bool ReadBoolean()

Returns

bool

The boolean value that was read.

ReadChar()

Reads a JSON string that must contain exactly one character.

public char ReadChar()

Returns

char

The character encoded in the JSON string.

ReadEndArray()

Reads the closing token for a JSON array.

public void ReadEndArray()

ReadNameSeparator()

Reads the name/value separator between a JSON property name and value.

public void ReadNameSeparator()

ReadNumberToken()

Reads the next JSON number token without converting it to a numeric type.

public string ReadNumberToken()

Returns

string

The raw number token as text.

ReadRawValue()

Reads the next JSON value and returns its raw JSON text.

public string ReadRawValue()

Returns

string

The raw JSON representation of the next value.

ReadRequiredBase64Bytes()

Reads a required base64-encoded JSON string value.

public byte[] ReadRequiredBase64Bytes()

Returns

byte[]

The decoded bytes.

ReadRequiredString()

Reads a required JSON string value.

public string ReadRequiredString()

Returns

string

The decoded string value.

ReadStartArray()

Reads the opening token for a JSON array.

public void ReadStartArray()

ReadStartObject()

Reads the opening token for a JSON object.

public void ReadStartObject()

ReadString()

Reads a JSON string value that may be null.

public string? ReadString()

Returns

string

The decoded string value, or null when the next token is a JSON null literal.

ReadValueSeparator()

Reads the separator between consecutive JSON values.

public void ReadValueSeparator()

SkipValue()

Skips over the next JSON value.

public void SkipValue()

TryReadEndArray()

Attempts to read the closing token for a JSON array.

public bool TryReadEndArray()

Returns

bool

true if the array terminator was consumed; otherwise, false.

TryReadEndObject()

Attempts to read the closing token for a JSON object.

public bool TryReadEndObject()

Returns

bool

true if the object terminator was consumed; otherwise, false.

TryReadNull()

Attempts to read a JSON null literal.

public bool TryReadNull()

Returns

bool

true if a null literal was consumed; otherwise, false.