Design schema

Rendering

Design schema

A design is a versioned JSON document, validate it, migrate it, render it.

The shape: a body with rows; each row has columns; each column holds a list of blocks. A block carries a type and its values.

ts
import { validateDesign, migrateDesign } from "email-craft-sdk";

const design = validateDesign(json);   // throws on an invalid design
const current = migrateDesign(json);   // upgrade an older schema version

Existing Unlayer designs convert to this schema automatically when you loadDesign them.

validateDesign or migrateDesign

  • validateDesign only accepts a design already at schema_version: "2.0". Use it on designs your own code produced.
  • migrateDesign takes anything stored earlier: a design with no version, an older version, or Unlayer's numeric schemaVersion. It upgrades it, renames old camelCase keys such as contentWidth to snake_case, then validates. A 2.0 design is only validated, so calling it every time is safe.
  • Both throw a Zod error when the design does not fit.

Rules that often fail

  • body.content_width must be a number from 320 to 1200. "600px" fails on a 2.0 design.
  • Rows, columns and blocks each need an id. Every row needs at least one column, and a column's width is 0 to 100.
  • A block's type must be one of the 20 known types, such as heading, text, raw-html, navigation or custom, and it needs a values object.
  • The result is a parsed copy: keys the schema does not know are left out of it.

Each level is described on the design object and block object pages.