JSON, YAML and XML

Load lists and single objects from JSON, YAML or XML files into the same kind of typed record.

On this page
csharp
[DataSource("Authors", "./authors.json")]
public sealed record Author(string Id, string Name);

Pick the format with the file extension. For TOML, CSV or another format, teach Bevel with a small reader (Teach Bevel a new format). The record stays the same. Every format is strict: a missing value without a default fails the build (see Required values and Unique).

A root array gives IReadOnlyList<Author>.

Data/Authors/authors.jsonjson
[
  { "id": "khalid", "name": "Khalid Abuhakmeh" },
  { "id": "ada", "name": "Ada Sterling" }
]
csharp
[DataSource("Authors", "./authors.json")]
public sealed record Author(string Id, string Name);

Read it in a page

razor
@foreach (var link in Data.Navigation) { <a href="@link.Href">@link.Label</a> }
<h1>@Data.Site.Title</h1>

Single objects (Site) are T. Lists are IReadOnlyList<T>.