Microsoft.FSharpLu
0.10.30
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.FSharpLu --version 0.10.30
NuGet\Install-Package Microsoft.FSharpLu -Version 0.10.30
<PackageReference Include="Microsoft.FSharpLu" Version="0.10.30" />
paket add Microsoft.FSharpLu --version 0.10.30
#r "nuget: Microsoft.FSharpLu, 0.10.30"
// Install Microsoft.FSharpLu as a Cake Addin #addin nuget:?package=Microsoft.FSharpLu&version=0.10.30 // Install Microsoft.FSharpLu as a Cake Tool #tool nuget:?package=Microsoft.FSharpLu&version=0.10.30
FSharp.Json
Newtonsoft's Json.Net is the library of choice for Json serialization. Unfortunately
the built-in converters generate rather verbose and ugly Json for certain F# data types like
discriminated unions and option types. The module Microsoft.FSharpLu.Json
provides more succinct
serialization for those types.
To use our serializer open the module with
open Microsoft.FSharpLu.Json
To serialize an object using the default Json.Net format you can use
Default.serialize
.
Option type
The following examples shows how JSon.net serializes
a simple value of type (int option) list
:
Default.serialize [Some 5; None; Some 6]
val it : string = "
[
{
"Case": "Some",
"Fields": [ 5 ]
},
null,
{
"Case": "Some",
"Fields": [ 6 ]
}
]"
Using the compact serializer provided by FSharpLu.Json the same objects gets serialized instead as a one-liner heterogeneous array:
Compact.serialize [Some 5; None; Some 6]
val it : string = "[ 5, null, 6 ]"
Discriminated unions
Now let's take a look at simple field-less discriminated unions.
Take for instance the type type SimpleDu = Foo | Bar
.
The value Foo
gets serialized by Json.Net as follows:
Value | Default (Json.net) | Compact |
---|---|---|
Foo |
{ "Case": "Foo" } |
"Foo" |
Discriminated unions with fields
Our serializer also supports generic discrimnated unions with fields for instance take the following binary Tree example:
type 'a Tree = Leaf of 'a | Node of 'a Tree * 'a Tree
let x = Node (Node((Leaf 1), (Leaf 4)), Leaf 6)
Default Json.net serialization:
Default.serialize x
val it : string = "
{
"Case": "Node",
"Fields": [
{
"Case": "Node",
"Fields": [
{
"Case": "Leaf",
"Fields": [ 1 ]
},
{
"Case": "Leaf",
"Fields": [ 4 ]
}
]
},
{
"Case": "Leaf",
"Fields": [ 6 ]
} ]
}"
where FSharpLu.Json produces the more succinct and easier to read:
Compact.serialize x
val it : string = "
{
"Node": [
{
"Node": [
{ "Leaf": 1 },
{ "Leaf": 4 }
]
},
{ "Leaf": 6 }
]
}"
Backward compatibility with Json.Net
FSharpLu.Json incldues a third serializer called BackwardCompatible
. While it produces the same
Json as the compact serializer it can deserialize Json in both compact format as well as the
default format produced by the stock JSon.net serializer.
This is helpful when migrating projects from Json.Net to FSharpLu.Json as it lets you deserialize Json that was produced by earlier versions of your code.
Expressed more formally this serializer verifies the following properties:
BackwardCompatible.serialize
=Compact.serialize
Default.serialize >> BackwardCompatible.deserialize
=id
Compact.serialize >> BackwardCompatible.deserialize
=id
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net452 is compatible. net46 was computed. net461 is compatible. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.2
- FSharp.Core (>= 4.5.4)
- System.ValueTuple (>= 4.4.0)
-
.NETFramework 4.6.1
- FSharp.Core (>= 4.5.4)
- System.Configuration (>= 2.0.5)
- System.Configuration.ConfigurationManager (>= 4.5.0)
- System.ValueTuple (>= 4.4.0)
-
.NETFramework 4.6.2
- FSharp.Core (>= 4.5.4)
- System.Configuration (>= 2.0.5)
- System.Configuration.ConfigurationManager (>= 4.5.0)
- System.ValueTuple (>= 4.4.0)
-
.NETFramework 4.7.2
- FSharp.Core (>= 4.5.4)
- System.Configuration (>= 2.0.5)
- System.Configuration.ConfigurationManager (>= 4.5.0)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- FSharp.Core (>= 4.5.4)
- System.Collections.NonGeneric (>= 4.3.0)
- System.Configuration (>= 2.0.5)
- System.Configuration.ConfigurationManager (>= 4.5.0)
- System.Diagnostics.TextWriterTraceListener (>= 4.3.0)
- System.Diagnostics.TraceSource (>= 4.3.0)
- System.Diagnostics.Tracing (>= 4.3.0)
- System.IO.FileSystem.Watcher (>= 4.3.0)
- System.Security.Permissions (>= 4.5.0)
- System.Security.Principal (>= 4.3.0)
- System.Security.Principal.Windows (>= 4.5.1)
- System.ValueTuple (>= 4.5.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Microsoft.FSharpLu:
Package | Downloads |
---|---|
Microsoft.FSharpLu.Windows
Windows specific helpers requiring the full .NetFramework |
|
FsFirestore
Functional F# library to access Firestore database via Google Cloud Platform (GCP) or Firebase Project. |
|
Microsoft.FSharpLu.Azure
Azure Management Helpers API for F# |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.11.7 | 34,188 | 6/24/2021 |
0.11.6 | 27,661 | 10/20/2019 |
0.11.5 | 3,216 | 8/17/2019 |
0.11.4 | 1,472 | 8/3/2019 |
0.11.3 | 1,106 | 8/1/2019 |
0.11.2 | 1,110 | 7/25/2019 |
0.11.1 | 1,171 | 7/20/2019 |
0.11.0 | 908 | 7/15/2019 |
0.10.33 | 1,096 | 6/25/2019 |
0.10.32 | 1,045 | 6/7/2019 |
0.10.31 | 1,379 | 3/20/2019 |
0.10.30 | 995 | 3/7/2019 |
0.10.29 | 3,884 | 12/27/2018 |
0.10.28 | 813 | 12/15/2018 |
0.10.27 | 10,111 | 6/9/2018 |
0.10.26 | 1,223 | 5/16/2018 |
0.10.21 | 1,518 | 4/27/2018 |
0.10.4 | 1,193 | 2/28/2018 |
0.10.3 | 1,376 | 8/28/2017 |
0.9.6050.26231 | 3,039 | 7/29/2016 |
Signed assemblies and nuget package