#### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt 'index')
### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt 'Abblix\.Jwt')

## JsonWebTokenExtensions Class

Provides extension methods for handling JSON data within JWTs\.

```csharp
public static class JsonWebTokenExtensions
```

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → JsonWebTokenExtensions
### Methods

## JsonWebTokenExtensions\.GetArrayOfStrings\(this JsonObject, string\) Method {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStrings(thisSystem.Text.Json.Nodes.JsonObject,string)}

Retrieves an array of strings from a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') based on a specified property name\.
This method supports both single string values and arrays of strings\.

```csharp
public static System.Collections.Generic.IEnumerable<string> GetArrayOfStrings(this System.Text.Json.Nodes.JsonObject json, string name);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStrings(thisSystem.Text.Json.Nodes.JsonObject,string).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') from which to retrieve the array of strings\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStrings(thisSystem.Text.Json.Nodes.JsonObject,string).name}

The property name to retrieve the values from\.

#### Returns
[System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')  
An enumerable of strings if the property exists; otherwise, an empty enumerable\.

### Remarks
This method is useful for JWT claims or other JSON structures where a property may contain either
a single string value or an array of strings\.

## JsonWebTokenExtensions\.GetArrayOfStringsOrNull\(this JsonObject, string\) Method {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStringsOrNull(thisSystem.Text.Json.Nodes.JsonObject,string)}

Retrieves an array of strings from a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') based on a specified property name,
or returns `null` if the property does not exist\.

```csharp
public static System.Collections.Generic.IEnumerable<string>? GetArrayOfStringsOrNull(this System.Text.Json.Nodes.JsonObject json, string name);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStringsOrNull(thisSystem.Text.Json.Nodes.JsonObject,string).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') from which to retrieve the array of strings\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.GetArrayOfStringsOrNull(thisSystem.Text.Json.Nodes.JsonObject,string).name}

The property name to retrieve the values from\.

#### Returns
[System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')  
An enumerable of strings if the property exists; otherwise, `null`\.

### Remarks
This method is useful when distinguishing between a missing property \(`null`\) and a property
that is present but empty\. It supports both single string values and arrays of strings\.

## JsonWebTokenExtensions\.GetSpaceSeparatedStrings\(this JsonObject, string\) Method {#Abblix.Jwt.JsonWebTokenExtensions.GetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string)}

Retrieves a collection of strings from a space\-separated string stored in a specified property of a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject')\.

```csharp
public static System.Collections.Generic.IEnumerable<string> GetSpaceSeparatedStrings(this System.Text.Json.Nodes.JsonObject json, string name);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.GetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') from which to retrieve the space\-separated strings\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.GetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string).name}

The name of the property containing the space\-separated string\.

#### Returns
[System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')  
An enumerable of strings if the property exists and contains values; otherwise, an empty enumerable\.

### Remarks
This method simplifies extracting multiple values from a single string property, common in JWT and OAuth scenarios\.

## JsonWebTokenExtensions\.GetUnixTimeSeconds\(this JsonObject, string\) Method {#Abblix.Jwt.JsonWebTokenExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string)}

Retrieves a [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value from a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') based on
a property stored as Unix time seconds\.

```csharp
public static System.Nullable<System.DateTimeOffset> GetUnixTimeSeconds(this System.Text.Json.Nodes.JsonObject json, string name);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') from which to retrieve the date/time value\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.GetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string).name}

The property name containing the Unix time seconds\.

#### Returns
[System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')  
A nullable [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') representing the date and time of the specified property,
or `null` if the property is not present or cannot be converted\.

### Remarks
Unix time seconds are widely used for representing date and time in JSON objects, especially in JWTs\.
This method simplifies retrieving such values by converting them directly to [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')\.

## JsonWebTokenExtensions\.SetArrayOrString\(this JsonObject, string, IEnumerable\<string\>\) Method {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrString(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_)}

Sets a property in a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') with a value that can be either a single string or an array of strings,
depending on the number of items in the provided enumerable\.

```csharp
public static void SetArrayOrString(this System.Text.Json.Nodes.JsonObject json, string name, System.Collections.Generic.IEnumerable<string> values);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrString(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to modify\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrString(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).name}

The name of the property to set\.

###### `values` [System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrString(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).values}

The enumerable of string values to set as the property's value\.

### Remarks
This method is versatile for JWT or JSON handling where a property may accept both single and multiple values\.

## JsonWebTokenExtensions\.SetArrayOrStringOrNull\(this JsonObject, string, IEnumerable\<string\>\) Method {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrStringOrNull(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_)}

Sets a property on a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to either a single string, a JSON array of strings, or `null`,
depending on the contents of the provided [values](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebTokenExtensions#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrStringOrNull(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).values 'Abblix\.Jwt\.JsonWebTokenExtensions\.SetArrayOrStringOrNull\(this System\.Text\.Json\.Nodes\.JsonObject, string, System\.Collections\.Generic\.IEnumerable\<string\>\)\.values') collection\.

```csharp
public static void SetArrayOrStringOrNull(this System.Text.Json.Nodes.JsonObject json, string name, System.Collections.Generic.IEnumerable<string>? values);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrStringOrNull(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to update\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrStringOrNull(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).name}

The name of the property to set\.

###### `values` [System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1') {#Abblix.Jwt.JsonWebTokenExtensions.SetArrayOrStringOrNull(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).values}

The collection of string values to assign\. If `null`, the property is set to `null`\.
If the collection contains a single value, it is stored as a string; if multiple values, as a JSON array\.

### Remarks
This method is useful for serializing claims or properties where the value can be a single string,
an array of strings, or omitted entirely \(null\), such as in JWT payloads or OpenID Connect claims\.

## JsonWebTokenExtensions\.SetSpaceSeparatedStrings\(this JsonObject, string, IEnumerable\<string\>\) Method {#Abblix.Jwt.JsonWebTokenExtensions.SetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_)}

Sets a property in a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') with a value represented as a space\-separated string from an enumerable of strings\.

```csharp
public static void SetSpaceSeparatedStrings(this System.Text.Json.Nodes.JsonObject json, string name, System.Collections.Generic.IEnumerable<string> value);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.SetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to modify\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.SetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).name}

The name of the property to set\.

###### `value` [System\.Collections\.Generic\.IEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1 'System\.Collections\.Generic\.IEnumerable\`1') {#Abblix.Jwt.JsonWebTokenExtensions.SetSpaceSeparatedStrings(thisSystem.Text.Json.Nodes.JsonObject,string,System.Collections.Generic.IEnumerable_string_).value}

The enumerable of string values to join into a space\-separated string\.

### Remarks
This method is useful for setting JWT claims or other JSON properties that accept a list of values as a single space\-separated string\.

## JsonWebTokenExtensions\.SetUnixTimeSeconds\(this JsonObject, string, Nullable\<DateTimeOffset\>\) Method {#Abblix.Jwt.JsonWebTokenExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_)}

Sets a [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value in a [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject'), stored as Unix time seconds\.

```csharp
public static void SetUnixTimeSeconds(this System.Text.Json.Nodes.JsonObject json, string name, System.Nullable<System.DateTimeOffset> value);
```
#### Parameters

###### `json` [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') {#Abblix.Jwt.JsonWebTokenExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).json}

The [System\.Text\.Json\.Nodes\.JsonObject](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonobject 'System\.Text\.Json\.Nodes\.JsonObject') to modify\.

###### `name` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Jwt.JsonWebTokenExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).name}

The property name under which to store the Unix time seconds\.

###### `value` [System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1') {#Abblix.Jwt.JsonWebTokenExtensions.SetUnixTimeSeconds(thisSystem.Text.Json.Nodes.JsonObject,string,System.Nullable_System.DateTimeOffset_).value}

The [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') value to set\. If `null`,
                the property will be removed from the JSON object\.

### Remarks
Storing dates as Unix time seconds is a common practice in JWTs and other JSON structures\.
This method facilitates setting such values by converting [System\.DateTimeOffset](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset 'System\.DateTimeOffset') to Unix time seconds\.

## JsonWebTokenExtensions\.ToJsonElement\(this JsonNode\) Method {#Abblix.Jwt.JsonWebTokenExtensions.ToJsonElement(thisSystem.Text.Json.Nodes.JsonNode)}

Converts a JsonNode to a JsonElement\.

```csharp
public static System.Text.Json.JsonElement ToJsonElement(this System.Text.Json.Nodes.JsonNode? jsonNode);
```
#### Parameters

###### `jsonNode` [System\.Text\.Json\.Nodes\.JsonNode](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonnode 'System\.Text\.Json\.Nodes\.JsonNode') {#Abblix.Jwt.JsonWebTokenExtensions.ToJsonElement(thisSystem.Text.Json.Nodes.JsonNode).jsonNode}

The JsonNode to convert\.

#### Returns
[System\.Text\.Json\.JsonElement](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonelement 'System\.Text\.Json\.JsonElement')  
The converted JsonElement\.

## JsonWebTokenExtensions\.ToJsonNode\(this JsonElement\) Method {#Abblix.Jwt.JsonWebTokenExtensions.ToJsonNode(thisSystem.Text.Json.JsonElement)}

Converts a JsonElement to a JsonNode, allowing for more dynamic manipulation of the JSON structure\.

```csharp
public static System.Text.Json.Nodes.JsonNode? ToJsonNode(this System.Text.Json.JsonElement jsonElement);
```
#### Parameters

###### `jsonElement` [System\.Text\.Json\.JsonElement](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonelement 'System\.Text\.Json\.JsonElement') {#Abblix.Jwt.JsonWebTokenExtensions.ToJsonNode(thisSystem.Text.Json.JsonElement).jsonElement}

The JsonElement to convert\.

#### Returns
[System\.Text\.Json\.Nodes\.JsonNode](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.nodes.jsonnode 'System\.Text\.Json\.Nodes\.JsonNode')  
The converted JsonNode\.

### Remarks
This method is useful when you need to convert from a structured JsonElement to a more flexible JsonNode\.
