Table of Contents

Class JsonShape

Namespace
JsonAssertions
Assembly
JsonAssertions.TUnit.dll

Framework-agnostic shape predicates for a resolved JsonElement: its value kind, and, for arrays, its length. Like JsonValueComparison, the predicates return false on a kind mismatch rather than throwing, so a caller can render a "found a String, expected an array" diagnostic instead of catching an exception.

public static class JsonShape
Inheritance
JsonShape
Inherited Members

Methods

IsArrayOfLength(JsonElement, int)

Reports whether element is a JSON array with exactly length elements.

public static bool IsArrayOfLength(JsonElement element, int length)

Parameters

element JsonElement
length int

Returns

bool

IsBoolean(JsonElement)

Reports whether element is a JSON boolean of either value. JSON's true and false are distinct JsonValueKinds, so a "this field is a bool, either value" assertion cannot be expressed via IsKind(JsonElement, JsonValueKind) alone.

public static bool IsBoolean(JsonElement element)

Parameters

element JsonElement

Returns

bool

IsEmptyArray(JsonElement)

Reports whether element is a JSON array with no elements.

public static bool IsEmptyArray(JsonElement element)

Parameters

element JsonElement

Returns

bool

IsKind(JsonElement, JsonValueKind)

Reports whether element is of the given kind.

public static bool IsKind(JsonElement element, JsonValueKind kind)

Parameters

element JsonElement
kind JsonValueKind

Returns

bool

IsNonEmptyArray(JsonElement)

Reports whether element is a JSON array with at least one element.

public static bool IsNonEmptyArray(JsonElement element)

Parameters

element JsonElement

Returns

bool

IsNonEmptyString(JsonElement)

Reports whether element is a JSON string with a non-zero length. A non-string kind returns false; an empty JSON string ("") returns false.

public static bool IsNonEmptyString(JsonElement element)

Parameters

element JsonElement

Returns

bool