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

## SingleOrArrayConverter\<T\> Class

Reads and writes a JSON value that may be either a single element of [T](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Json.SingleOrArrayConverter_T_#Abblix.Utils.Json.SingleOrArrayConverter_T_.T 'Abblix\.Utils\.Json\.SingleOrArrayConverter\<T\>\.T') or an array of
such elements, exposing it uniformly to \.NET as `T[]`\. On write, a single\-element array is emitted as a bare
scalar \(not an array\), matching the OAuth 2\.0 / OpenID Connect convention used for parameters such as
`aud` and `response_type`\.

```csharp
public class SingleOrArrayConverter<T> : System.Text.Json.Serialization.JsonConverter<T[]>
```
#### Type parameters

###### `T` {#Abblix.Utils.Json.SingleOrArrayConverter_T_.T}

The element type\. A converter for [T](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Json.SingleOrArrayConverter_T_#Abblix.Utils.Json.SingleOrArrayConverter_T_.T 'Abblix\.Utils\.Json\.SingleOrArrayConverter\<T\>\.T') must be available in the
            serializer options\.

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → [System\.Text\.Json\.Serialization\.JsonConverter](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter 'System\.Text\.Json\.Serialization\.JsonConverter') → [System\.Text\.Json\.Serialization\.JsonConverter&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter-1 'System\.Text\.Json\.Serialization\.JsonConverter\`1')[T](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Json.SingleOrArrayConverter_T_#Abblix.Utils.Json.SingleOrArrayConverter_T_.T 'Abblix\.Utils\.Json\.SingleOrArrayConverter\<T\>\.T')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter-1 'System\.Text\.Json\.Serialization\.JsonConverter\`1') → SingleOrArrayConverter\<T\>
### Methods

## SingleOrArrayConverter\<T\>\.Read\(Utf8JsonReader, Type, JsonSerializerOptions\) Method {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions)}

Reads and converts the JSON to a string array\.
If the JSON token is a single string, it returns an array containing one element\.
If it is an array of strings, it converts each element and returns them in an array\.

```csharp
public override T[]? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);
```
#### Parameters

###### `reader` [System\.Text\.Json\.Utf8JsonReader](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.utf8jsonreader 'System\.Text\.Json\.Utf8JsonReader') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).reader}

The reader from which to read the JSON document\.

###### `typeToConvert` [System\.Type](https://learn.microsoft.com/en-us/dotnet/api/system.type 'System\.Type') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).typeToConvert}

The type to convert\. Expected to be a string array\.

###### `options` [System\.Text\.Json\.JsonSerializerOptions](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions 'System\.Text\.Json\.JsonSerializerOptions') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).options}

Options for the serializer\.

#### Returns
[T](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Json.SingleOrArrayConverter_T_#Abblix.Utils.Json.SingleOrArrayConverter_T_.T 'Abblix\.Utils\.Json\.SingleOrArrayConverter\<T\>\.T')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array')  
An array of strings parsed from the JSON input\.

#### Exceptions

[System\.Text\.Json\.JsonException](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonexception 'System\.Text\.Json\.JsonException')  
Thrown if an unexpected token type is encountered\.

## SingleOrArrayConverter\<T\>\.Write\(Utf8JsonWriter, T\[\], JsonSerializerOptions\) Method {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Write(System.Text.Json.Utf8JsonWriter,T[],System.Text.Json.JsonSerializerOptions)}

Writes a string array to a JSON writer\.
If the array contains a single string, it writes it as a single string value\.
If it contains multiple strings, it writes them as an array of strings\.

```csharp
public override void Write(System.Text.Json.Utf8JsonWriter writer, T[]? value, System.Text.Json.JsonSerializerOptions options);
```
#### Parameters

###### `writer` [System\.Text\.Json\.Utf8JsonWriter](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.utf8jsonwriter 'System\.Text\.Json\.Utf8JsonWriter') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Write(System.Text.Json.Utf8JsonWriter,T[],System.Text.Json.JsonSerializerOptions).writer}

The writer to which the JSON will be written\.

###### `value` [T](https://www.abblix.com/en/docs/api/abblix-utils/Abblix.Utils.Json.SingleOrArrayConverter_T_#Abblix.Utils.Json.SingleOrArrayConverter_T_.T 'Abblix\.Utils\.Json\.SingleOrArrayConverter\<T\>\.T')[\[\]](https://learn.microsoft.com/en-us/dotnet/api/system.array 'System\.Array') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Write(System.Text.Json.Utf8JsonWriter,T[],System.Text.Json.JsonSerializerOptions).value}

The string array to write\.

###### `options` [System\.Text\.Json\.JsonSerializerOptions](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions 'System\.Text\.Json\.JsonSerializerOptions') {#Abblix.Utils.Json.SingleOrArrayConverter_T_.Write(System.Text.Json.Utf8JsonWriter,T[],System.Text.Json.JsonSerializerOptions).options}

Options for the serializer\.

#### Exceptions

[System\.ArgumentNullException](https://learn.microsoft.com/en-us/dotnet/api/system.argumentnullexception 'System\.ArgumentNullException')  
Thrown if the writer or value is null\.
