Home JsonNodeExtensions Class
JsonNodeExtensions Class
Cancel

JsonNodeExtensions Class

Namespace: Json.Path

Inheritance: JsonNodeExtensions 🡒 object

Useful extensions for System.Text.Json.Nodes.JsonNode.

Methods

TryGetSingleValue(this JsonNode node, out JsonNode value)

Ensures a System.Text.Json.Nodes.JsonNode only represents a single value.

Declaration

1
public static bool TryGetSingleValue(this JsonNode node, out JsonNode value)
ParameterTypeDescription
nodeJsonNode 
valueout JsonNode 

Returns

Within the context of this library, a Json.Path.NodeList may be stored inside a System.Text.Json.Nodes.JsonNode. Some operations, such as expression addition, require that a single value is provided.

This method checks to see if the underlying value of a JsonNode is a NodeList. If not, it simply sets to the JsonNode and returns true. If the underlying value is a NodeList and it only contains a single value, it sets to that JsonNode and return true. Otherwise, it returns false.

Remarks

Though a bit complex, this method can be very important for functions that require single values as inputs rather than nodelists since function composition is possible (e.g. min(max(@,0),10)) and functions return nodelists.

TryGetSingleValue(this NodeList nodeList, out JsonNode value)

Ensures a Json.Path.NodeList only represents a single value.

Declaration

1
public static bool TryGetSingleValue(this NodeList nodeList, out JsonNode value)
ParameterTypeDescription
nodeListNodeList 
valueout JsonNode 

Returns

Within the context of this library, a Json.Path.NodeList may be stored inside a System.Text.Json.Nodes.JsonNode. Some operations, such as expression addition, require that a single value is provided.

This method checks to see if the underlying value of a JsonNode is a NodeList. If not, it simply sets to the JsonNode and returns true. If the underlying value is a NodeList and it only contains a single value, it sets to that JsonNode and return true. Otherwise, it returns false.

Remarks

Though a bit complex, this method can be very important for functions that require single values as inputs rather than nodelists since function composition is possible (e.g. min(max(@,0),10)) and functions return nodelists.

TryGetValue(this JsonNode node, out T value)

Declaration

1
public static bool TryGetValue(this JsonNode node, out T value)

Returns

Contents