Build a custom UI from JSON
If you are developing a modern web application (using React, Vue, Svelte, or Next.js, for instance), you can directly consume the compiled JSON data produced by Gram and connect it to your own user interface components.
While the parser initially produces a raw Abstract Syntax Tree (AST), @gram-lang/kitchen and @gram-lang/analyzer transform it into a structured, render-ready JSON object. This guide explains how to extract this data and design your UI around two core pillars: rendering the recipe view and presenting time (relative execution timeline or real-world calendar schedule).
-
Fetch the JSON data
Section titled “Fetch the JSON data”Gram is designed to run in any JavaScript environment (Node.js, Edge runtimes, or directly in the browser). To obtain the complete, enriched JSON representation of a recipe, combine its three foundational packages:
General data model structure
Section titled “General data model structure”The resulting JSON object encapsulates the entire recipe deterministically:
title(string): The recipe name (defined by# Title).meta(object): Key-value metadata (e.g.author,portions,yield).shopping_list(array): Aggregated list of all ingredients, ready for procurement.sections(array): Cooking instructions divided into self-contained sections.metrics(object): Overall metrics (preparationTime,activeTimein minutes, as well as mass and nutrition when analyzed).miseEnPlace(array): Operational preparation breakdown and durations for each section.tasks(object): Complete task dependency graph with durations, used by the scheduler.schedule(object): Default schedule calculated fromtasks(totalTime,idleTime, scheduled blocks, and working-day breakdown).
-
Render the recipe: ingredients and instructions
Section titled “Render the recipe: ingredients and instructions”Each entry in
sectionsholds its own lists of ingredients (ingredients), cookware (cookware), and instructions (steps).Rendering this in your UI consists of mapping over these arrays within your front-end components.
Example: recursive component in React
Section titled “Example: recursive component in React”Here is an implementation illustrating how to render
stepsand their inline tokens with React:By connecting each
typediscriminator to your own components, you maintain full control over styling, accessibility, and interactivity. -
Present time: relative timeline or calendar schedule
Section titled “Present time: relative timeline or calendar schedule”Gram offers two complementary approaches to represent time depending on your application’s user experience:
- The relative execution timeline: expresses time in minutes starting from $t = 0$. Ideal for an in-kitchen live cooking mode or a continuous step timeline.
- The calendar schedule: projects steps onto concrete dates, wall-clock times, and distinct kitchen visits. Ideal for meal planning and production organization.
Option A: Relative timeline (minutes from start)
Section titled “Option A: Relative timeline (minutes from start)”To render a continuous timeline, use the blocks in
recipe.schedule.blocks. If you want to explore different scheduling strategies dynamically without recompiling the recipe, passrecipe.tasksdirectly tolayout():All
startandendvalues are expressed in relative minutes. You can let users switch strategies interactively: total recipe time shifts (schedule.totalTime), but active prep work remains invariant (schedule.preparationTime).Option B: Real-world calendar schedule (dates and clock times)
Section titled “Option B: Real-world calendar schedule (dates and clock times)”When you have a target serving time and cooking availability (such as cooking only between 8 a.m. and 10 p.m.), the engine projects the recipe onto a real-world calendar using
project(), then organizes visits by day and visit usingrunSheet():The data structure returned by
runSheet()is identical to the output ofgram plan --format json. It allows you to build a full calendar view in about thirty lines of TypeScript:Key data structure properties
Section titled “Key data structure properties”day.visits[]: active kitchen visits. Each entry providesstartandend(exact minutes before service),startLocalandendLocal(wall-clock timestamps in the target time zone), recipe section indexes (sections), task IDs (tasks), andwindow/fixedByindicating scheduling margins.day.threads[]: passive resting processes (proofing, resting, chilling) that continue unattended after a visit (visitis its index within the day), with their planned duration (planned), allowed range (range), and expected completion (toLocal).day.entries[]: ordered sequence of all blocks for the day (active and passive), useful for drawing a detailed custom timeline or day view.sheet.adjustments[]andsheet.diagnostics[]: lists of passive rests that were adjusted to fit your availability, and unresolved scheduling constraints that triggered warnings.