Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
323 stars 44 forks source link

Support Tuples #170

Closed lucasteles closed 10 months ago

lucasteles commented 10 months ago

It is common to represent tuples in TypeScript (also json) using fixed-size arrays

So it would be great to have these options here

Eg:

let tuple2 = "one", 2
let tuple3 = true, "value", 42

JsonSerializer.Serialize tuple2 // ['one', 2]
JsonSerializer.Serialize tuple3 // [true, 'value', 42]
Tarmil commented 10 months ago

These are already supported by FSharp.SystemTextJson. You just need to make sure to use the serializer options.

let tuple2 = "one", 2
let tuple3 = true, "value", 42

let options = JSonFSharpOptions().ToJsonSerializerOptions()

JsonSerializer.Serialize(tuple2, options) // ['one', 2]
JsonSerializer.Serialize(tuple3, options) // [true, 'value', 42]