JsonTag.FSharp
0.1.7
dotnet add package JsonTag.FSharp --version 0.1.7
NuGet\Install-Package JsonTag.FSharp -Version 0.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonTag.FSharp" Version="0.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonTag.FSharp" Version="0.1.7" />
<PackageReference Include="JsonTag.FSharp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JsonTag.FSharp --version 0.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JsonTag.FSharp, 0.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JsonTag.FSharp@0.1.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JsonTag.FSharp&version=0.1.7
#tool nuget:?package=JsonTag.FSharp&version=0.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
json-tag
F# support for JSON#.
Configures FSharp.SystemTextJson to use the JSON# convention.
Install
dotnet add package JsonTag.FSharp
Usage
Define your discriminated unions:
type Shape =
| Circle of radius: float
| Rectangle of width: float * height: float
Serialize and deserialize:
let json = JsonSerializer.Serialize(Circle(radius = 4.0), JsonTagOptions.Default)
// {"#type":"Circle","radius":4}
let shape = JsonSerializer.Deserialize<Shape>(json, JsonTagOptions.Default)
Custom tag names (using FSharp.SystemTextJson's JsonName attribute):
type Vehicle =
| [<JsonName("Car")>] PersonalVehicle of make: string
| [<JsonName("Truck")>] TransportationVehicle of payloadTons: float
Apply to existing JsonFSharpOptions:
let myFSharpOptions = JsonFSharpOptions(unionEncoding = JsonUnionEncoding.UnwrapOption)
let options = JsonTagOptions.apply myFSharpOptions
ASP.NET Core / Giraffe:
builder.Services.ConfigureHttpJsonOptions(fun options ->
options.SerializerOptions <- JsonTagOptions.Default)
API
| Export | Description |
|---|---|
JsonTagOptions.Default |
Pre-configured JsonSerializerOptions |
JsonTagOptions.apply |
Applies #type convention to existing JsonFSharpOptions |
[<JsonName("X")>] |
Custom #type value on a union case (from FSharp.SystemTextJson) |
Known limitation
FSharp.SystemTextJson requires #type to be the first property in the JSON object. Out-of-order #type is not supported.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- FSharp.Core (>= 10.0.100)
- FSharp.SystemTextJson (>= 1.4.36)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.