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











































