Skip to main content

IR Schema

The gridwell IR (Intermediate Representation) is a JSON document that fully describes a table’s structure, content, and styling.

Design Principles

  1. Declarative — describes what to render, not how
  2. Flat where possible — uses indices/references, avoids deep nesting
  3. Typed values — cells carry typed data alongside formatted text
  4. Styling by reference — styles defined in a palette, referenced by ID
  5. Span-aware — row/column spans are first-class with explicit placeholders
  6. Versioned — ir_version allows future evolution

Top-Level Structure

{
  "ir_version": "1.0",
  "config": {...},
  "styles": {...},
  "header": {...},
  "column_spec": [...],
  "table": {...},
  "footer": {...},
  "extensions": {...}
}
Field Type Default Description
ir_version string required The IR version, "1.0" (below)
config Config required Table-level configuration
styles StylePalette {"defs": {}, "compositions": {}, "conditionals": []} The style palette: left out, or {}, for none
header Header? null Title, subtitle and extra header lines
column_spec array of ColumnSpec required One entry per column
table TableBlock required The column labels and the body
footer Footer? null Footnotes and source notes
extensions any? null Anything a producer wants to carry along. No writer reads it, and it round-trips unchanged; namespace its keys ("example.com/producer")

A field the IR doesn’t have is ignored, so a table written for a newer minor version still parses. Validation rejects a table whose values are wrong, not one with extra fields.

Versions

ir_version is MAJOR.MINOR: ASCII digits and a dot, nothing around them ("01.00" reads as 1.0). A minor version only adds to the IR; a major version may change it. This gridwell reads IR 1:

  • IR 1.0 is read as it is.
  • A newer minor version ("1.3") is read and rendered, with a NEWER_IR_VERSION warning: what that version added is left out. A field this gridwell doesn’t know is ignored, and a keyword value, length unit, color form or link scheme it doesn’t know is read as unset, with an IGNORED_VALUE warning.
  • Another major version ("2.0", "0.9") is refused: an IR_VERSION validation error, or, when the JSON doesn’t parse as IR 1, a parse error saying the version is why.
  • Anything else ("1", "1.0.0", " 1.0") is an IR_VERSION error.
Note

IR 1.0 is frozen. Great Tables’ own emitter and gridwell’s converters for gt and Great Tables write it, and a table written in IR 1.0 reads the same in every later gridwell that reads IR 1. IR 1 only grows, by minor versions.

IR versions

Version Status Schema What it adds
1.0 frozen ir-1.0.schema.json The first version

What a minor version may change

A minor version only adds, so that a gridwell that reads IR 1.0 reads every 1.x table, and draws it without what is new:

  • New fields, each optional, with a default that does what the earlier version did without it. A table written before the field existed reads the same, and an older gridwell ignores the field.
  • New content node types, for content whose loss leaves the rest readable. An older gridwell draws a node it doesn’t know as the node’s fallback, so a producer can say what to draw in its place (below), or as nothing.
  • New keyword values, length units, color forms and link schemes. An older gridwell reads a value it doesn’t know, in a table of the newer version, as unset: the field is left out or takes its default, and a link’s text is drawn without it.
  • New selector fields, which narrow the rows a conditional style matches. An older gridwell applies a style whose selector has a field it doesn’t know to no row, since it can’t tell which rows the field leaves out.

An older gridwell warns of each value and selector it leaves out (IGNORED_VALUE, IGNORED_SELECTOR).

A minor version never removes or renames a field, makes an optional one required or a required one optional, changes a default, or changes what a value already means. Nor does it relax a validation rule: a table that breaks one is invalid to every gridwell that reads IR 1. A table that uses a newer minor’s additions says so in its ir_version, since an older gridwell reads a new value as an error in a table of its own version. One that uses none of them can keep the earlier version.

Two changes would relax a rule, so they are left to IR 2, if they are made at all: a span from a group’s data rows into its summary rows (as gt’s HTML draws a group column’s cell over them), and a composition that extends another composition.

JSON Schema

The IR has a JSON Schema (draft 2020-12), for editors and for validators in other languages: ir-1.0.schema.json, at https://rich-iannone.github.io/gridwell/schema/ir-1.0.schema.json. gridwell schema prints it too. A table can name it in a "$schema" field, which gridwell ignores like any field it doesn’t know.

The schema describes the IR as an emitter should write it. Every table gridwell accepts fits it, as gridwell writes it back, and every table that fits it parses. It differs from gridwell in three ways:

  • Keywords are listed in their canonical spelling ("center", "line-through"). gridwell also reads them in any case, with spaces around them, and reads their aliases ("centre", "strikethrough").
  • What depends on the rest of the table is left to validation: whether a style id is defined, whether the spans fit, whether config matches the rows and columns, and the other structural rules. So are color names and the numbers in rgb() and hsl(): the schema checks a color’s form.
  • Fields it doesn’t list are allowed, as gridwell ignores them, and so are content nodes of types it doesn’t list. A table of a later IR 1.x version may also hold keyword values and forms the 1.0 schema doesn’t list, which gridwell reads as unset: check it against its own version’s schema.

One difference it can’t express: JSON Schema counts 1.0 and 1e2 as integers, and gridwell reads a count (table_cols, colspan, …) only when it is written as a whole number (1, 100).

Each later minor version gets a schema of its own, which accepts everything the earlier ones do.

Content Nodes

Cell content is an array of content nodes, each an object whose type says which:

Type Fields Description
text value, href Plain text; href makes it a link
styled_text value, style_id, href Text with a style applied (style_id may be null)
line_break — Line break within cell
footnote_mark ref, mark_text A footnote’s mark: ref is the footnote’s id, mark_text what is shown
image src, alt, width, height Inline image (below); alt, width and height may be null
raw format, value Markup for one format (below)

Every field is required except those that may be null, and href, which is left out of a run that isn’t a link. Only http, https and mailto URLs are links (INVALID_HREF), since a javascript: or file: one could run code or open a local file when it is followed.

A node of a type this gridwell doesn’t know parses, so a newer minor version can add node types. It may have a fallback, an array of content nodes drawn in its place by a gridwell that doesn’t know its type: a producer writing a node of a newer type can give, say, the text it stands for. Without one (or with null), the node is drawn as nothing. A fallback is validated like any content, and may itself hold nodes of unknown types, drawn as their fallbacks. The node is written back with all its fields when the IR is serialized again.

{
  "content": [
    { "type": "sparkline", "values": [3, 5, 2],
      "fallback": [{ "type": "text", "value": "3, 5, 2" }] }
  ]
}

Raw markup

A raw node’s value is markup in its format (html, latex, typst, rtf, …), written as it is by that format’s writer and dropped by the others. HTML is the exception: every format draws it, by turning its inline markup (bold, italic, colors, line breaks, images, …) into its own runs. The Output Formats guide lists what is drawn. Content may carry raw markup for several formats side by side (one version each); then each writer takes only its own, HTML included.

Raw markup is a trust boundary. A writer copies it into its output unchecked, so raw HTML can hold a script, and raw LaTeX, Typst or RTF can read files or run commands when the output is compiled or opened. For IR you don’t trust, render with the raw option off. Every format takes it. Then every format draws raw HTML the way formats other than HTML do, HTML included, and raw markup for other formats is dropped. An image’s src is another matter: HTML still writes it as it is (see Images).

Images

An image node’s src is drawn only when it is a data: URI (base64 or percent-encoded) holding a whole PNG, JPEG, GIF or SVG file. Writers never fetch a URL or read a path named by src, as the IR may come from anywhere. HTML is the exception: it writes src as given, and the browser loads it. An image a format can’t draw shows its alt text instead, and is warned of.

width and height are CSS lengths, and an image is sized the way a browser sizes an <img>. A side that is set is used. A side that isn’t keeps the image’s aspect ratio, and with neither set the image keeps its own size (1px = 0.75pt). em is relative to the text around the image.

Format Draws
HTML any src
SVG, Typst PNG, JPEG, GIF, SVG
DOCX PNG, JPEG, GIF
RTF PNG, JPEG
XLSX PNG, JPEG, GIF, alone in its cell or line, but not in a footnote (it is drawn over the cell)
LaTeX, PPTX, ANSI none (the alt text)

Data that is whole but corrupt inside (a broken compressed stream, say) gets past the check: depending on the format, the image may then show up blank, or the Typst compiler may reject the document.

Sections

  • Config — table-level configuration
  • Header — title, subtitle and header lines
  • Columns — column specification
  • Table Data — thead and tbody structure
  • Styles — style palette and references
  • Footer — footnotes and source notes
  • Validation — structural validation rules