JDeck.Xml 1.0.0

dotnet add package JDeck.Xml --version 1.0.0
                    
NuGet\Install-Package JDeck.Xml -Version 1.0.0
                    
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="JDeck.Xml" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JDeck.Xml" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="JDeck.Xml" />
                    
Project file
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 JDeck.Xml --version 1.0.0
                    
#r "nuget: JDeck.Xml, 1.0.0"
                    
#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 JDeck.Xml@1.0.0
                    
#: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=JDeck.Xml&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=JDeck.Xml&version=1.0.0
                    
Install as a Cake Tool

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 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.

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.