liveBook · Manning

Schema

As explained in F# in Action: A Revised Edition of Get Programming with F#

A schema is a formal description of the fields, structure, and types expected in a data resource.

A schema formally describes the fields, structure, and types expected in a data resource. In F#, a small sample dataset can define that schema and generate usable types while you edit code; a separate dataset can supply the actual runtime values. section 10.3

A practical schema workflow:

  • Provide representative sample rows so the tooling can infer fields and appropriate types. section 10.3
  • Keep the schema sample distinct from runtime data, which can be loaded from a larger file, database, or HTTP resource. section 10.3.2
  • Shape samples deliberately: include rows with and without optional fields so generated types represent the real data. section 10.3.4
  • Keep schema files under source control where possible, and map generated data-transfer types into richer domain models. section 10.3.4

A schema from a local JSON sample

type GuitarJson = JsonProvider<const(__SOURCE_DIRECTORY__ + "/sample-guitars.json")> The sample file defines the expected structure; runtime code can subsequently load a different inventory that matches it. section 10.3.2

type ManyGuitarsOverHttp =
    JsonProvider<"https://raw.githubusercontent.com/       #1
 isaacabraham/fsharp-in-action/main/
 sample-guitars.json"> 
let inventory = ManyGuitarsOverHttp.GetSamples()           #2
printfn $"You have {inventory.Length} guitars in stock."   #3
#1 Creates a schema based on a remote file
#2 Loads the sample data from that location
#3 Gets the length of the array of objects

This example contrasts creating a schema from a remote JSON file with loading its guitar data and reading the resulting collection. section 10.3.2

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains sample-based inference, edit-time type creation, runtime loading, optional fields, and schema-maintenance trade-offs.
Examples
Uses guitar JSON samples, local files, remote HTTP resources, optional fields, and larger runtime inventory files.
What you can do after
Apply it via F# type providers to create types from samples and load matching runtime data.
How it connects
Connects schema to type providers, JSON, runtime data loading, DTOs, and core domain models.

Also explained in

Compare how 44 books explain schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.