JDeck 1.0.0-beta-005
See the version list below for details.
dotnet add package JDeck --version 1.0.0-beta-005
NuGet\Install-Package JDeck -Version 1.0.0-beta-005
<PackageReference Include="JDeck" Version="1.0.0-beta-005" />
<PackageVersion Include="JDeck" Version="1.0.0-beta-005" />
<PackageReference Include="JDeck" />
paket add JDeck --version 1.0.0-beta-005
#r "nuget: JDeck, 1.0.0-beta-005"
#:package JDeck@1.0.0-beta-005
#addin nuget:?package=JDeck&version=1.0.0-beta-005&prerelease
#tool nuget:?package=JDeck&version=1.0.0-beta-005&prerelease
JDeck a System.Text.Json wrapper
JDeck is a Thoth.Json-like Json decoder based on System.Text.Json
in a single file with no external
dependencies. Plays well with other libraries that use System.Text.Json
like FSharp.SystemTextJson
Note: While JDeck has no dependencies to start working right away, it is recommended to use FsToolkit.ErrorHandling
Usage
For most F# types, you can use the Decode.auto
function to decode JSON as shown below:
#r "nuget: JDeck, 1.0.0-beta-*"
open JDeck
type Person = {
name: string
age: int
emails: string list
}
let json = """{"name": "Alice", "age": 30, "emails": ["alice@name.com", "alice@age.com"] }"""
let result: Result<Person, DecodeError> = Decoding.auto(json)
match result with
| Ok person -> printfn $"Person: %A{person}"
| Error err -> printfn $"Error: %A{err}"
In cases where the data is inconclusive, you deserialize Discriminated Unions or does not play well with F# immutability, you can create a manual decoder.
#r "nuget: JDeck, 1.0.0-beta-*"
open System.Text.Json
open JDeck
type Person = {
Name: string
Age: int
Emails: string list
}
type ServerResponse = { Data: Person; Message: string }
let personDecoder: Decoder<Person> = fun person -> decode {
let! name = person |> Required.Property.get("name", Optional.string)
and! age = person |> Required.Property.get("age", Required.int)
and! emails = person |> Required.Property.list("emails", Optional.string)
return {
Name = name |> Option.defaultValue "<missing name>"
Age = age
// Remove any optional value from the list
Emails = emails |> List.choose id
}
}
// Inconclusive data coming from the server
let person = """{"name": null, "age": 30, "emails": ["alice@name.com", "alice@age.com", null] }"""
let result: Result<ServerResponse, DecodeError> =
// ServerResponse will decode automatically while Person will use the custom decoder
Decoding.auto(
$$"""{ "data": {{person}}, "message": "Success" }""",
// Include your own decoder
JsonSerializerOptions(PropertyNameCaseInsensitive = true) |> Codec.useDecoder personDecoder
)
match result with
| Ok person -> printfn $"Person: %A{person}"
| Error err -> printfn $"Error: %A{err}"
Acknowledgements
Nothing is done in the void, in this case I'd like to thank the following libraries for their inspiration and ideas:
- Thoth.Json for the inspiration and a cross-runtime solution to JSON decoding, compatible with F#, JS, and Python.
- FsToolkit.ErrorHandling for the general mechanism for dealing with Result types and Computation expressions
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 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
.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 | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. 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. |
-
.NETStandard 2.0
- FSharp.Core (>= 9.0.100-beta.24466.6)
- System.Text.Json (>= 9.0.0)
-
net8.0
- FSharp.Core (>= 9.0.100-beta.24466.6)
-
net9.0
- FSharp.Core (>= 9.0.100-beta.24466.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on JDeck:
Package | Downloads |
---|---|
Perla.PkgManager
A Library under the Perla umbrella. This package provides a small Package Manager API to interact with the JSPM API to produce ImportMaps and and take them offline. It also powers the package management and importmap features of the Perla Dev Server. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-rc-006 | 117 | 8/23/2025 |
1.0.0-rc-005 | 117 | 8/20/2025 |
1.0.0-rc-004 | 115 | 8/20/2025 |
1.0.0-rc-003 | 272 | 7/12/2025 |
1.0.0-rc-002 | 48 | 7/11/2025 |
1.0.0-rc-001 | 59 | 7/11/2025 |
1.0.0-beta-006 | 285 | 11/22/2024 |
1.0.0-beta-005 | 80 | 11/22/2024 |
1.0.0-beta-004 | 81 | 11/21/2024 |
1.0.0-beta-003 | 75 | 11/20/2024 |
1.0.0-beta-002 | 77 | 11/19/2024 |
1.0.0-beta-001 | 71 | 11/19/2024 |