Home JsonPointer Struct
JsonPointer Struct
Cancel

JsonPointer Struct

Namespace: Json.Pointer

Inheritance: JsonPointer 🡒 ValueType 🡒 object

Implemented interfaces:

  • IEquatable<JsonPointer>

Represents a JSON Pointer as defined in RFC 6901. This implementation is optimized for minimal allocations.

Fields

NameTypeSummary
EmptyJsonPointerRepresents an empty JSON Pointer.

Properties

NameTypeSummary
ItemJsonPointerSegmentGets a segment from the pointer by index.
SegmentCountintGets the number of segments in the pointer.

Methods

Combine(JsonPointer other)

Combines this pointer with another pointer.

Declaration

1
public JsonPointer Combine(JsonPointer other)
ParameterTypeDescription
otherJsonPointerThe pointer to append

Returns

A new pointer representing the combination

Combine(params SegmentValueStandIn[] segments)

Combines this pointer with additional segments.

Declaration

1
public JsonPointer Combine(params SegmentValueStandIn[] segments)
ParameterTypeDescription
segmentsparams SegmentValueStandIn[]The segments to append

Returns

A new pointer representing the combination

Remarks

This method incurs allocation costs for string concatenation and array creation. For better performance with large numbers of segments, consider using Json.Pointer.JsonPointer.Parse(System.ReadOnlySpan{System.Char}).

Create(params SegmentValueStandIn[] segments)

Creates a new JSON Pointer from segments.

Declaration

1
public static JsonPointer Create(params SegmentValueStandIn[] segments)
ParameterTypeDescription
segmentsparams SegmentValueStandIn[]The segments to combine.

Returns

A new JSON Pointer.

Remarks

This method incurs allocation costs for string concatenation and array creation. For better performance with large pointers, consider using Json.Pointer.JsonPointer.Parse(System.ReadOnlySpan{System.Char}).

EndsWith(JsonPointer other)

Determines whether the current JSON pointer ends with the specified JSON pointer.

Declaration

1
public bool EndsWith(JsonPointer other)
ParameterTypeDescription
otherJsonPointerThe JSON pointer to compare with the end of the current pointer. Cannot be null.

Returns

true if the current JSON pointer ends with the specified pointer; otherwise, false.

Equals(JsonPointer other)

Compares this pointer with another pointer for equality.

Declaration

1
public bool Equals(JsonPointer other)

Returns

Equals(object obj)

Indicates whether this instance and a specified object are equal.

Declaration

1
public override bool Equals(object obj)
ParameterTypeDescription
objobjectThe object to compare with the current instance.

Returns

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

Evaluate(JsonElement element)

Evaluates this pointer against a JsonElement to find the referenced value.

Declaration

1
public JsonElement? Evaluate(JsonElement element)
ParameterTypeDescription
elementJsonElementThe root JsonElement to evaluate against

Returns

The referenced JsonElement if found, null otherwise

GetHashCode()

Returns the hash code for this instance.

Declaration

1
public override int GetHashCode()

Returns

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

GetLocal(int levels)

Gets the local pointer (trailing end) of this pointer.

Declaration

1
public JsonPointer GetLocal(int levels)
ParameterTypeDescription
levelsintThe number of segments to keep from the end. Defaults to 1.

Returns

A new pointer containing the specified number of trailing segments

GetParent(int levels)

Gets the parent pointer of this pointer.

Declaration

1
public JsonPointer? GetParent(int levels)
ParameterTypeDescription
levelsintThe number of ancestor levels to go back. Defaults to 1.

Returns

The parent pointer, or null if this is the root pointer

GetSegment(int index)

Gets a segment from the pointer by index.

Declaration

1
public JsonPointerSegment GetSegment(int index)
ParameterTypeDescription
indexintThe zero-based index of the segment

Returns

The segment as a JsonPointerSegment

Parse(string pointer)

Creates a new JSON Pointer from a string.

Declaration

1
public static JsonPointer Parse(string pointer)
ParameterTypeDescription
pointerstringThe string representation of the pointer.

Returns

A new JSON Pointer.

Parse(ReadOnlySpan<char> pointer)

Creates a new JSON Pointer from a span.

Declaration

1
public static JsonPointer Parse(ReadOnlySpan<char> pointer)
ParameterTypeDescription
pointerReadOnlySpan<char>The span representation of the pointer.

Returns

A new JSON Pointer.

StartsWith(JsonPointer other)

Determines whether the current JSON pointer starts with the specified JSON pointer.

Declaration

1
public bool StartsWith(JsonPointer other)
ParameterTypeDescription
otherJsonPointerThe JSON pointer to compare with the beginning of the current pointer. Cannot be null.

Returns

true if the current JSON pointer starts with the specified pointer; otherwise, false.

ToString()

Gets the string representation of this pointer.

Declaration

1
public override string ToString()

Returns

The pointer string

TryEvaluate(JsonNode root, out JsonNode result)

Evaluates the pointer over a System.Text.Json.Nodes.JsonNode.

Declaration

1
public bool TryEvaluate(JsonNode root, out JsonNode result)
ParameterTypeDescription
rootJsonNodeThe System.Text.Json.Nodes.JsonNode.
resultout JsonNodeThe result, if return value is true; null otherwise

Returns

true if a value exists at the indicate path; false otherwise.

TryGetSegment(int index, out JsonPointerSegment segment)

Attempts to get a segment from the pointer by index.

Declaration

1
public bool TryGetSegment(int index, out JsonPointerSegment segment)
ParameterTypeDescription
indexintThe zero-based index of the segment
segmentout JsonPointerSegmentThe segment if found; default otherwise

Returns

True if the segment was found; false otherwise

TryParse(string pointer, out JsonPointer result)

Attempts to create a new JSON Pointer from a string.

Declaration

1
public static bool TryParse(string pointer, out JsonPointer result)
ParameterTypeDescription
pointerstringThe string representation of the pointer.
resultout JsonPointerThe resulting pointer.

Returns

true if the pointer was successfully created; false otherwise.

TryParse(ReadOnlySpan<char> pointer, out JsonPointer result)

Attempts to create a new JSON Pointer from a span.

Declaration

1
public static bool TryParse(ReadOnlySpan<char> pointer, out JsonPointer result)
ParameterTypeDescription
pointerReadOnlySpan<char>The span representation of the pointer.
resultout JsonPointerThe resulting pointer.

Returns

true if the pointer was successfully created; false otherwise.

Contents