Skip to content

Data formats

The JSON shapes that flow between pipeline stages, and the YAML schema for the ingredient database. This page complements the per-package references — it illustrates what the data concretely looks like when processed by Gram functions.

The parser transforms raw recipe text into an Abstract Syntax Tree:

---
title: 'Crepes'
---

## Batter

Mix @flour{200g} and @milk{200ml}.

getAST() returns this structure. Byte offsets (loc) are omitted above for brevity — every node except RecipeAST carries a loc object. See the parser API reference for the complete list of node interfaces and the ASTNodeType enum.

2. Compiled & analyzed recipes (@gram-lang/kitchen, @gram-lang/analyzer)

Section titled “2. Compiled & analyzed recipes (@gram-lang/kitchen, @gram-lang/analyzer)”

compile() produces a CompilationResult; analyze() returns that same base shape enriched with physical mass conversions, baker’s percentages, and nutritional metrics (AnalyzedCompilationResult).

{
  "generator": "@gram-lang/kitchen@1.5.0",
  "title": "Crepes",
  "slug": "crepes",
  "meta": { "title": "Crepes" },
  "registry": {
    "ingredients": {
      "flour": { "id": "flour", "name": "flour" },
      "milk": { "id": "milk", "name": "milk" }
    },
    "cookware": {}
  },
  "shopping_list": [
    {
      "id": "flour",
      "name": "flour",
      "qty": 200,
      "unit": "g",
      "_usageIds": ["1"]
    },
    {
      "id": "milk",
      "name": "milk",
      "qty": 200,
      "unit": "ml",
      "_usageIds": ["2"]
    }
  ],
  "cookware": [],
  "sections": [
    {
      "title": "Batter",
      "retro_planning": null,
      "ingredients": [
        { "id": "flour", "_usageId": "1", "qty": 200, "unit": "g" },
        { "id": "milk", "_usageId": "2", "qty": 200, "unit": "ml" }
      ],
      "cookware": [],
      "steps": [
        {
          "type": "step",
          "content": [
            "Mix ",
            { "id": "flour", "_usageId": "1", "qty": 200, "unit": "g" },
            " and ",
            { "id": "milk", "_usageId": "2", "qty": 200, "unit": "ml" },
            "."
          ]
        }
      ]
    }
  ],
  "warnings": [],
  "metrics": {
    "preparationTime": 2,
    "activeTime": 2
  },
  "miseEnPlace": [
    { "section": 0, "duration": 2, "items": [ { "kind": "gather", "target": "ingredient", "count": 2, "duration": 2 } ] }
  ],
  "tasks": {
    "tasks": [
      { "id": "s0.prep", "kind": "prep", "section": 0, "duration": { "nominal": 2 }, "items": [ { "kind": "gather", "target": "ingredient", "count": 2, "duration": 2 } ], "after": [] },
      { "id": "s0.0", "kind": "step", "section": 0, "step": 0, "duration": { "nominal": 2 }, "after": [] }
    ],
    "sections": [ { "day": 0 } ]
  },
  "schedule": {
    "miseEnPlace": "perSection",
    "rests": "shortest",
    "totalTime": 4,
    "activeTime": 2,
    "preparationTime": 2,
    "idleTime": 0,
    "blocks": [
      { "kind": "prep", "task": "s0.prep", "section": 0, "start": 0, "end": 2 },
      { "kind": "step", "task": "s0.0", "section": 0, "step": 0, "start": 2, "end": 4 }
    ],
    "days": [ { "day": 0, "start": 0, "end": 4, "sections": [0] } ]
  }
}

The compiled recipe exposes generator (which compiler generated it), miseEnPlace (operational prep tasks and durations per section), tasks (the neutral task graph), and schedule (the default theoretical schedule laid out from it; alternative schedules are generated via layout(tasks, options)).

Note the compiler’s StepToken vocabulary inside content: narrative text is a bare string; ingredients, cookware, and intermediate references share the Usage structure (no type field, identified by the presence of an id); timers, temperatures, target states (checkpoint, since 1.5.0: { type, state, note? }), comments, and declarations each carry an explicit lowercase type. This distinction from the parser’s PascalCase ASTNodeType is intentional: it describes compiled output, not parsed source syntax. See How to build a custom UI for a tutorial on consuming this structure in frontend frameworks.

v1.5.0 A timer token carries raw (the duration as written inside the braces) and minutes (the scheduled duration, or the midpoint of a range). quantity and unit remain populated in the smallest written unit (1h20 produces 80 min) for backwards compatibility, while pre-1.5 single-unit formats (1.5h) stay unchanged. Unrecognized timers keep only raw (plus name and isPassive) so views can display them as written.

{ "type": "timer", "raw": "1h30", "quantity": { "type": "single", "value": 90 }, "unit": "min", "minutes": 90 }
{ "type": "timer", "raw": "1h30-2h", "quantity": { "type": "range", "value": 105, "range": { "min": 90, "max": 120 } }, "unit": "min", "minutes": 105 }
{ "type": "timer", "raw": "1:30" }

v1.5.0 A sum of quantities (@flour{1 cup + 1 tbsp}) adds parts to its Usage: each written term with qty (a number or QuantityValue), unit, and minus: true for subtracted terms. parts is the source of truth; qty and unit retain a compatibility summary:

  • Single unit family: qty and unit hold the total, in the smallest written unit when terms share a scale ({1 cup + 1 tbsp} → 17 tbsp), or in ml / g otherwise. Any range term makes the total a range.
  • Multiple families (a volume and a weight, or unknown units): qty is omitted and unit holds the written expression ("1 cup + 20 g"), similar to text quantities ({a pinch}). Read parts instead of parsing this string.
  • Invalid (INVALID_QUANTITY): parts only, with neither qty nor unit.
{ "id": "flour", "_usageId": "1", "qty": 17, "unit": "tbsp", "parts": [ { "qty": 1, "unit": "cup" }, { "qty": 1, "unit": "tbsp" } ] }
{ "id": "sugar", "_usageId": "2", "qty": 14, "unit": "tbsp", "parts": [ { "qty": 1, "unit": "cup" }, { "qty": 2, "unit": "tbsp", "minus": true } ] }
{ "id": "rice", "_usageId": "3", "unit": "1 cup + 20 g", "parts": [ { "qty": 1, "unit": "cup" }, { "qty": 20, "unit": "g" } ] }
{ "id": "oil", "_usageId": "4", "parts": [ { "qty": 1, "unit": "cup" }, { "qty": 20, "unit": "g", "minus": true } ] }

The same fields appear on a reference (&dough{1 kg + 200 g}) and a composite parent (<@oranges{1 lb + 4 oz}). In the shopping list, a sum counts as separate mentions: its terms join the entries of their unit, and an entry whose amounts include a range keeps qty as its middle plus range: { min, max }, added bound by bound.

When a recipe imports sub-modules via the @use directive, finalizeComposed() decorates the standard CompilationResult into a ComposedCompilationResult. It adds module metadata to both the root payload and individual spliced sections:

{
  "title": "Lemon Tart",
  "modules": [
    {
      "binding": "dough",
      "uri": "/bases/sweet-pastry-dough.gram",
      "title": "Sweet Pastry Dough",
      "meta": { "title": "Sweet Pastry Dough" },
      "scaleFactor": 1.5,
      "mode": "inline"
    }
  ],
  "sections": [
    {
      "title": "Sweet Pastry Dough",
      "module": {
        "binding": "dough",
        "uri": "/bases/sweet-pastry-dough.gram",
        "title": "Sweet Pastry Dough",
        "mode": "inline"
      },
      "steps": [ "/* spliced steps from the imported module */" ]
    },
    {
      "title": "Assembly",
      "steps": [ "/* host steps */" ]
    }
  ]
}
  • modules: Array of all imported module contributors (ModuleInfo), detailing local binding name, source URI, resolved scale factor, and execution mode ("inline" or "stocked").
  • section.module: Present on any section spliced in from an import (ComposedSection), preserving traceability for user interfaces and custom renderers.

The database passed to validateIngredientDatabase() or analyze() is a flat Record<string, IngredientData> keyed by ingredient slug. The gram CLI additionally accepts (and unwraps) an optional top-level ingredients: key:

# With the optional wrapper (scaffolded by default via gram init)
ingredients:
  flour:
    name: "All-purpose flour"
    aliases: ["farine"]
    category: "Grains"
    physical:
      density: 0.59       # g/mL — bridges volume units ("1 cup") to mass in grams
      yield: 1.0          # fraction (0, 1] — net/gross ratio after peeling or trimming
      unit_weight: 120    # grams per "unit" (e.g. "1 flour" if used bare)
    nutrition:            # all values per 100 g of raw ingredient
      calories: 364       # in kcal
      protein: 10.3       # in grams
      carbs: 76.3         # in grams
      fat: 1.0            # in grams
      sugar: 0.3          # in grams
      fiber: 2.7          # in grams
      sodium: 2           # in milligrams (mg)

physical and nutrition blocks are both optional — an entry without either remains valid (it simply contributes no mass or nutritional data, surfacing as missingMassIngredients or a MISSING_MACROS warning). Only name is strictly required. The sub-fields nutrition.calories, protein, carbs, and fat are required whenever nutrition is declared; sugar, fiber, sodium, sat_fat, mono_fat, poly_fat, and alcohol are optional.

Units matter and must be strictly observed: calories is kcal, sodium is in milligrams (mg), and every other nutrient is in grams (g) — all evaluated per 100 g of the raw ingredient. The canonical set, units, and ordering are governed by the NUTRIENTS table exported by @gram-lang/analyzer.

Data structure of the run sheet (@gram-lang/scheduler), as returned by runSheet() and emitted by gram plan --format json under the runSheet property. Example for a recipe scheduled with a target serving time:

{
  "mode": "calendar",
  "serveAt": "2026-10-17T20:00",
  "timeZone": "Europe/Paris",
  "recipes": [
    {
      "title": "Pistachio raspberry entremets",
      "miseEnPlace": "perSection",
      "totalWork": 45,
      "days": [
        {
          "date": "2026-10-16",
          "daysBefore": 1,
          "visits": [
            {
              "start": -1585, "end": -1560,
              "startLocal": "2026-10-16T13:35", "endLocal": "2026-10-16T14:00",
              "sections": [2],
              "tasks": ["s2.prep", "s2.0", "s2.1"],
              "window": { "advance": 335, "earliest": -1920, "earliestLocal": "2026-10-16T08:00" }
            }
          ],
          "threads": [
            { "visit": 0, "task": "s2.1.t0", "section": 2, "step": 1,
              "from": -1560, "to": -840, "planned": 720,
              "range": { "min": 720, "max": 2880 } }
          ],
          "entries": ["…every block of the day…"]
        }
      ]
    }
  ],
  "adjustments": [],
  "diagnostics": []
}
  • Times start, end, from and to are minutes from the service (negative before it), exact, in a plan with a serving time or without. *Local fields (minute-exact wall clock) and date come with a serving time only.
  • mode: "relative" is the same structure for a recipe with no serving time: no serveAt, no date, no window.
  • totalWork is the minutes of your own work, mise en place included.
  • miseEnPlace is the mode the plan was made in (perSection, perDay or upfront): the run sheet reads it to decide what goes in each visit’s mise en place.
  • Types and the meaning of each field: runSheet in the scheduler reference.