Logo Xantham

Decoder — JSON to DecodedResult

Decoder is the layer below XanthamTree. It is responsible only for reading a Xantham JSON file off disk and applying the standard compression and sanitization passes before producing a DecodedResult.

You usually don't need to call into Decoder directly — XanthamTree does it for you — but it's exposed for tooling and tests.

The simple path

let result = Decoder.read "./schema.json"

match result with
| Ok decoded ->
    printfn
        "Loaded %i types and %i exported declarations."
        decoded.TypeMap.Count
        decoded.ExportTypeMap.Count
| Error e -> eprintfn "Decode failed: %s" e

Decoder.read is a proxy that constructs a default Settings and calls readWithSettings.

Settings

Decoder.Settings controls the three optional passes the decoder runs:

Field

Default

Effect

InputFile

(required)

Path to the .json file produced by the extractor.

PerformHealthCheck

true in DEBUG, false otherwise

Walks the type map, verifies that every referenced TypeKey is reachable, and prints a report.

Compress

true

Collapses redundant entries in the type/export maps.

Sanitize

true

Replaces cyclic TypeKeys with obj so generators don't need to detect cycles themselves.

Construct settings with the Create static method:

let settings =
    Decoder.Settings.Create(
        inputFile = "./schema.json",
        performHealthCheck = true,
        compress = true,
        sanitize = false)

let decoded = Decoder.readWithSettings settings

DecodedResult

The shape returned on success:

The wire format itself (Schema.EncodedResult) lives in Xantham.Common.

Health check

When enabled, the health check answers the question "are all referenced TypeKeys present in the type map?". It distinguishes:

The report is printed to stdout. The status emojis (✔️ / ) are part of the printed output, not the return value.

namespace Xantham
namespace Xantham.Decoder
val result: Result<DecodedResult,string>
module Decoder from Xantham.Decoder
val read: fileName: string -> Result<DecodedResult,string>
<summary> Decode a xantham produced <c>.json</c> file. This is a proxy function that creates a <c>Settings</c> object using the default values and the supplied <c>fileName</c> which is then passed to <c>readWithSettings</c>. </summary>
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
val decoded: DecodedResult
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
DecodedResult.TypeMap: TypeMap
<summary> All structural types referenced anywhere in the source, keyed by &lt;c&gt;TypeKey&lt;/c&gt;. </summary>
property Map.Count: int with get
DecodedResult.ExportTypeMap: ExportTypeMap
<summary> All exported declarations, keyed by &lt;c&gt;TypeKey&lt;/c&gt;. </summary>
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>
val e: string
val eprintfn: format: Printf.TextWriterFormat<'T> -> 'T
val settings: Decoder.Settings
type Settings = { InputFile: string PerformHealthCheck: bool Compress: bool Sanitize: bool } static member Create: inputFile: string * ?performHealthCheck: bool * ?compress: bool * ?sanitize: bool -> Settings
<summary> Settings for the Decoder. </summary>
<category index="6">Runtime</category>
static member Decoder.Settings.Create: inputFile: string * ?performHealthCheck: bool * ?compress: bool * ?sanitize: bool -> Decoder.Settings
val decoded: Result<DecodedResult,string>
val readWithSettings: settings: Decoder.Settings -> Result<DecodedResult,string>
<summary> Decode a xantham produced <c>.json</c> file with the settings provided. </summary>

Type something to start searching.