TupleAsJsonArray 1.0.1

Convert C# Tuple to/from JSON Array

Install-Package TupleAsJsonArray -Version 1.0.1
dotnet add package TupleAsJsonArray --version 1.0.1
<PackageReference Include="TupleAsJsonArray" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TupleAsJsonArray --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

TupleAsJsonArray

Convert C# Tuple to/from JSON Array

About

  1. Serialize Tuple and ValueTuples to JSON Array
  2. Deserialize JSON Arrays as Tuples and ValueTuples
  3. Bridges the gap between JS Destructuring assignment and C# ValueTuples.

Using

.NET C#

// 1. Import Library
using TupleAsJsonArray;

// 2. Set Up Json Serializer Options
var options = new JsonSerializerOptions
{
    Converters =
    {
        new TupleConverterFactory(),
    }
};

// 3. Serialize Tuples to Array
var jsonArray = JsonSerializer.Serialize((1, 2, 3, 4), options);

// 4. Deserialize Arrays to Tuples
var (a, b, c, d) = JsonSerializer.Deserialize<(int, int, int, int)>("[1, 2, 3, 4]", options);

JavaScript

// Tuples in Models will now show up as arrays
// that you can destructure
const [a, b, c, d] = modelFromServer.TupleParam;

TupleAsJsonArray

Convert C# Tuple to/from JSON Array

About

  1. Serialize Tuple and ValueTuples to JSON Array
  2. Deserialize JSON Arrays as Tuples and ValueTuples
  3. Bridges the gap between JS Destructuring assignment and C# ValueTuples.

Using

.NET C#

// 1. Import Library
using TupleAsJsonArray;

// 2. Set Up Json Serializer Options
var options = new JsonSerializerOptions
{
    Converters =
    {
        new TupleConverterFactory(),
    }
};

// 3. Serialize Tuples to Array
var jsonArray = JsonSerializer.Serialize((1, 2, 3, 4), options);

// 4. Deserialize Arrays to Tuples
var (a, b, c, d) = JsonSerializer.Deserialize<(int, int, int, int)>("[1, 2, 3, 4]", options);

JavaScript

// Tuples in Models will now show up as arrays
// that you can destructure
const [a, b, c, d] = modelFromServer.TupleParam;

  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 69 5/31/2020