Home JsonPath Class
JsonPath Class
Cancel

JsonPath Class

Namespace: Json.Path

Inheritance: JsonPath 🡒 object

Represents a JSON Path.

Properties

NameTypeSummary
IsSingularboolGets whether the path is a singular path. That is, it can only return a nodelist containing at most a single value.
RootJsonPathGets a JSON Path with only a global root and no selectors, namely $.
ScopePathScopeGets the scope of the path.
SegmentsPathSegment[]Gets the segments of the path.

Methods

Append(string name)

Appends a new segment with the specified name to the current JSON path and returns the resulting path.

Declaration

1
public JsonPath Append(string name)
ParameterTypeDescription
namestringThe name of the segment to append to the JSON path. This value cannot be null or empty.

Returns

A new instance of the JsonPath class that includes the appended segment.

Remarks

This method can be used to build more complex JSON paths by successively appending named segments. The original JsonPath instance remains unchanged; this method returns a new instance with the additional

Append(int index)

Appends an array index selector to the current JSON path, enabling access to a specific element within a JSON array.

Declaration

1
public JsonPath Append(int index)
ParameterTypeDescription
indexintThe zero-based index of the element to select from the array. Must be within the bounds of the target array.

Returns

A new JsonPath instance that includes the appended index selector.

Remarks

Use this method to navigate to a particular element in a JSON array by its index. Supplying an

BuildString(StringBuilder builder)

Builds a string representation of the path using a System.Text.StringBuilder.

Declaration

1
public void BuildString(StringBuilder builder)
ParameterTypeDescription
builderStringBuilderThe string builder.

Evaluate(JsonNode root, PathEvaluationOptions options)

Evaluates the path against a JSON instance.

Declaration

1
public PathResult Evaluate(JsonNode root, PathEvaluationOptions options)
ParameterTypeDescription
rootJsonNodeThe root of the JSON instance.
optionsPathEvaluationOptionsEvaluation options.

Returns

The results of the evaluation.

Parse(string source, PathParsingOptions options)

Parses a Json.Path.JsonPath from a string.

Declaration

1
public static JsonPath Parse(string source, PathParsingOptions options)
ParameterTypeDescription
sourcestringThe source string.
optionsPathParsingOptions(optional) The parsing options.

Returns

The parsed path.

ToString()

Returns a string that represents the current object.

Declaration

1
public override string ToString()

Returns

A string that represents the current object.

TryParse(string source, out JsonPath path, PathParsingOptions options)

Parses a Json.Path.JsonPath from a string.

Declaration

1
public static bool TryParse(string source, out JsonPath path, PathParsingOptions options)
ParameterTypeDescription
sourcestringThe source string.
optionsout JsonPath(optional) The parsing options.
pathPathParsingOptionsThe parsed path, if successful; otherwise null.

Returns

True if successful; otherwise false.

Contents