Table of Contents

Struct RawJson

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

Represents the exact UTF-8 bytes of a JSON value for deferred deserialization.

[GenerateShape]
public struct RawJson : IEquatable<RawJson>, IShapeable<RawJson>
Implements
Inherited Members

Remarks

Construction borrows unvalidated bytes. The caller must keep borrowed storage alive and unchanged. Call ToOwned() before releasing that storage. The built-in converter always deserializes an owned copy and validates values before writing them. A default instance has an empty payload, not a JSON null, and cannot be serialized.

Constructors

RawJson(ReadOnlySequence<byte>)

Initializes a new instance of the RawJson struct.

public RawJson(ReadOnlySequence<byte> json)

Parameters

json ReadOnlySequence<byte>

The borrowed, unvalidated UTF-8 JSON bytes.

Properties

IsOwned

Gets a value indicating whether this instance has an independent, owned lifetime.

public readonly bool IsOwned { get; }

Property Value

bool

Json

Gets the exact JSON payload, including its original token spelling.

public readonly ReadOnlySequence<byte> Json { get; }

Property Value

ReadOnlySequence<byte>

Methods

Equals(RawJson)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(RawJson other)

Parameters

other RawJson

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToOwned()

Copies borrowed storage and retains the owned copy in this instance.

public RawJson ToOwned()

Returns

RawJson

An independently owned payload, or this instance if it already owns its storage.

Remarks

The copy uses GC-owned storage, never a rented buffer. Repeated calls on a mutable instance reuse the copy.

ToString()

Returns the fully qualified type name of this instance.

public override readonly string ToString()

Returns

string

The fully qualified type name.

Operators

explicit operator RawJson(ReadOnlySequence<byte>)

Borrows a sequence of JSON bytes.

public static explicit operator RawJson(ReadOnlySequence<byte> json)

Parameters

json ReadOnlySequence<byte>

The borrowed bytes.

Returns

RawJson

The raw JSON descriptor.

explicit operator RawJson(byte[])

Borrows an array containing JSON bytes.

public static explicit operator RawJson(byte[] json)

Parameters

json byte[]

The borrowed bytes.

Returns

RawJson

The raw JSON descriptor.

explicit operator RawJson(Memory<byte>)

Borrows a memory region containing JSON bytes.

public static explicit operator RawJson(Memory<byte> json)

Parameters

json Memory<byte>

The borrowed bytes.

Returns

RawJson

The raw JSON descriptor.

explicit operator RawJson(ReadOnlyMemory<byte>)

Borrows a memory region containing JSON bytes.

public static explicit operator RawJson(ReadOnlyMemory<byte> json)

Parameters

json ReadOnlyMemory<byte>

The borrowed bytes.

Returns

RawJson

The raw JSON descriptor.

implicit operator ReadOnlySequence<byte>(RawJson)

Gets the raw JSON sequence.

public static implicit operator ReadOnlySequence<byte>(RawJson json)

Parameters

json RawJson

The raw JSON descriptor.

Returns

ReadOnlySequence<byte>

The borrowed or owned JSON payload.