JDeck.Xml
1.0.0
dotnet add package JDeck.Xml --version 1.0.0
NuGet\Install-Package JDeck.Xml -Version 1.0.0
<PackageReference Include="JDeck.Xml" Version="1.0.0" />
<PackageVersion Include="JDeck.Xml" Version="1.0.0" />
<PackageReference Include="JDeck.Xml" />
paket add JDeck.Xml --version 1.0.0
#r "nuget: JDeck.Xml, 1.0.0"
#:package JDeck.Xml@1.0.0
#addin nuget:?package=JDeck.Xml&version=1.0.0
#tool nuget:?package=JDeck.Xml&version=1.0.0
JDeck a System.Text.Json wrapper
JDeck is a Thoth.Json-like Json decoder based on System.Text.Json 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"
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"
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 | 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. |
-
net10.0
- FSharp.Core (>= 10.0.100)
- XmlEssentials (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 65 | 11/30/2026 |
### Added
- **JDeck.Xml:** DOM decoder and encoder package over XmlEssentials (`XmlDocument`/`XmlElement`/`XmlNode`) with required, optional, and value-optional decoders, element and attribute navigation, collection and error-collecting forms, full encoders, a `decode` computation builder, and `Codec` registration for automatic serialization.
- **JDeck.Xml:** Namespace-aware decoding and encoding. `Element.get` and `Attribute.get` overloads on `Required`, `Optional`, and `VOptional` take a namespace URI plus a local name and match that URI exactly, and `Decode.decodeAtKeyInNamespace` / `tryDecodeAtKeyInNamespace` give the same match directly. `Encode.elementNS`, `textElementNS`, `attributeNS`, and `namespaceDeclaration` build namespaced elements and attributes. The local-name overloads keep matching any namespace, and an unprefixed attribute is in no namespace.