Home JsonNodeExtensions Class
JsonNodeExtensions Class
Cancel

JsonNodeExtensions Class

Namespace: Json.Logic

Inheritance: JsonNodeExtensions 🡒 object

Provides fuzzy-logic extensions for System.Text.Json.Nodes.JsonNode values.

Methods

Flatten(this JsonNode root)

Flattens an array into its root components (removes intermediate arrays).

Declaration

1
public static IEnumerable<JsonNode> Flatten(this JsonNode root)
ParameterTypeDescription
rootJsonNodeThe element.

Returns

Returns a single array with all of the intermediate arrays removed.

IsTruthy(this JsonNode node)

Determines whether a value can be considered as true.

Declaration

1
public static bool IsTruthy(this JsonNode node)
ParameterTypeDescription
nodeJsonNodeThe element.

Returns

true if the value is:

  • a non-empty array
  • a non-empty string
  • a non-zero number
  • true

    1
    
          	`false` otherwise
    

LooseEquals(this JsonNode a, JsonNode b)

Provides loose equality comparison of System.Text.Json.Nodes.JsonNode values.

Declaration

1
public static bool LooseEquals(this JsonNode a, JsonNode b)
ParameterTypeDescription
aJsonNodeThe first value.
bJsonNodeThe second value.

Returns

true if the values are loosely equal; false otherwise.

Remarks

Adapted from @marvindv/jsonlogic_rs.

Numberify(this JsonNode node)

Provides a loose-cast to a number.

Declaration

1
public static decimal? Numberify(this JsonNode node)
ParameterTypeDescription
nodeJsonNodeThe node.

Returns

A string representation of the value as follows:

  • empty string returns 0
  • all other strings try to parse a number from the value
  • true returns 1
  • false returns 0 - numbers are unchanged
  • null, objects, and arrays return null (not numberifiable)

Stringify(this JsonNode node)

Provides a loose-cast to a string.

Declaration

1
public static string Stringify(this JsonNode node)
ParameterTypeDescription
nodeJsonNodeThe node.

Returns

A string representation of the value as follows:

  • arrays are the elements stringified and comma-delimited
  • null returns the empty string
  • objects return null (not stringifiable) - numbers and booleans return their JSON equivalents
  • strings are unchanged
Contents