# Names and tables

### Names as keys

Some services send a name as the key and its number as the value. AdGuard Home's top domains are `[{"apple.com": 3}, {"google.com": 2}]`: a list of one-field objects, where the domain is the key. `"entries": true` turns each object into rows of `{ "key", "value" }`, so the rest of the rule can read them:

```json
{ "each": "top_queried_domains", "entries": true, "limit": 5,
  "fields": { "label": "key", "value": "value" } }
```

`each` can also name a single object, such as `{"apple.com": 3, "google.com": 2}`, which gives one row per field. `entries` comes first, so `where`, `sort` and `limit` work on the rows it makes. An object's fields have no order of their own, so they come in key order; add a `sort` for any other. Keys with dots, colons or slashes, like `https://dns10.quad9.net:443/dns-query`, stay whole, since `key` is read as a field, not a path.

### Parallel arrays

Open-Meteo sends hourly weather as parallel arrays. Add `"zip": true` to turn them into rows in array order:

```json
{ "each": "hourly", "zip": true,
  "fields": { "label": "time", "values[0]": "temperature_2m" } }
```

For `{"hourly":{"time":["09:00","10:00"],"temperature_2m":[52.1,53]}}`, this makes two columns rows. Use the same rule in `derive` or a card map. `where`, `sort`, `limit` and `buckets` work on the rows as usual.

A null leaves that field missing. For example, null pollen values match `exists: false`. Fields that are not arrays are ignored. Unequal arrays stop at the shortest array. `zip` needs one `each` path and cannot be combined with `entries`.


### Names and exact times

`{record|first_word}` takes the first whitespace-separated word. `{record|rest_words}` takes the remaining text, with surrounding whitespace removed. Spaces and tabs both separate the first word; the remaining names stay together. For a local DNS record such as `192.0.2.10 printer.example`, these give the address and hostname. Derive the name first, then sort rows by it.

`{time|time}` draws an exact local 24-hour clock time with seconds, such as `17:03:12`, from Unix seconds or a supported date. It stays fixed as an answer ages, making it useful for query logs. Include the date separately when showing older history. The `hour` filter includes a zone on a repeated daylight-saving hour so the two hours have different labels.

### Turning a table round

Some services answer one way round when a chart wants the other. Lunch Money's budget summary lists each category with its months inside it; a [`columns`](https://legatobar.com/docs/card-numbers.md#columns) chart of income against spending wants each month with its categories. Two options do it, after `where` and before `sort`:

- `flatten`: a path to each element's own list, which takes the element's place. Each item of that list gets the element it came from as `parent`, so it can still be told apart. Items that aren't objects are left out. A GitHub contribution calendar's weeks flatten into its days for a [heatmap](https://legatobar.com/docs/card-time.md#heatmap). An object at the path gives its fields as `{key, value}` rows, for a service that sends each slot's counts by name: Pi-hole's clients over time, `{"timestamp": …, "data": {"192.0.2.10": 41}}`, flatten into one row per client per slot.
- `group`: a path to a value the rows share. One row per value, in the order each first appears, as `{ "key", "count", "rows" }`. `sort`, `limit` and `fields` then work on the groups, and an aggregate with `"of": "rows"` totals each one.

A field's name can be a path into a list the card takes, so `values[0]` and `values[1]` fill a column's two values. This is the chart on the Net Worth example: income from income categories, spending from the rest, January to this month:

```json
{ "each": "summary.categories",
  "lookup": { "from": "cats.categories", "by": "id", "on": "category_id", "as": "category" },
  "where": { "all": [ { "path": "category.is_group", "not": true }, { "path": "category.exclude_from_totals", "not": true } ] },
  "flatten": "occurrences", "group": "start_date",
  "fields": {
    "label": { "template": "{key|month}" },
    "values[0]": { "add": [ { "sum": "other_activity", "of": "rows", "where": { "path": "parent.category.is_income", "equals": true } },
                            { "sum": "recurring_activity", "of": "rows", "where": { "path": "parent.category.is_income", "equals": true } } ],
                   "scale": -1, "round": 0 },
    "values[1]": { "add": [ { "sum": "other_activity", "of": "rows", "where": { "path": "parent.category.is_income", "not": true } },
                            { "sum": "recurring_activity", "of": "rows", "where": { "path": "parent.category.is_income", "not": true } } ],
                   "round": 0 } } }
```

`summary` here is `/v2/summary?start_date={date.year_start}&end_date={date.month_end}&include_occurrences=true`, and `cats` is `/v2/categories?format=flattened`.

`min` and `max` also take `rank`, a list of values from best to worst, for values whose order isn't numeric. Uptime Kuma's status is 1 up, 3 maintenance, 2 pending, 0 down, so `{ "max": "monitor_status", "of": "monitors", "rank": [1, 3, 2, 0] }` is the worst status of any monitor.

Any rule can then be adjusted:

| Option | Example | Does |
| --- | --- | --- |
| `values` | `{ "path": "blocking.blocking", "values": { "enabled": "ok", "disabled": "warning" } }` | Looks the value up. Entries are literal values or an object containing only `{ "template": … }`; other rule objects are not evaluated here. |
| `default` | `"default": "unknown"` | Used when there's no value, or no `values` entry for it. Like a lookup entry, it can be a literal or a sole `template` object. |
| `match` | `{ "path": "config.data.meta", "match": "ctime=([0-9]+)" }` | Searches the value's text with a regular expression and keeps the first capture group (or the whole match without one), as a number when it reads as one: `creation-qemu=11.1.3,ctime=1793983411` → 1793983411. It comes before `values`, `scale` and `round`; no match is no value, so `default` applies. Page-authored `match` patterns stop after a short execution budget; inputs above 65,536 UTF-16 code units are not matched. A budget limit acts like no match, so the rule’s `default` applies. Parameter patterns use the same budget and refuse a value on timeout. |
| `clock` | `{ "path": "[\"Sleep start\"]", "clock": 12, "round": 2 }` | A moment (ISO 8601, Unix seconds, or a date and time like `2026-10-29 22:56:24 -0500`) as hours of the day on this Mac: 10:56 PM is 22.93. Times before this hour (0–23) are the next day's and count from 24, so with `12` a wake-up at 8:01 AM is 32.02 and a night stays in order. For a [ranges](https://legatobar.com/docs/card-numbers.md#ranges) card with `unit` `clock`. Applied before `scale`. |
| `scale`, `offset`, `round` | `{ "path": "climate_state.inside_temp", "scale": 1.8, "offset": 32, "round": 0 }` | Scaled, then offset, then rounded to that many decimals: here, °C to °F. |

Template placeholders take filters after a `|`, and filters chain:

| Filter | Example | Gives |
| --- | --- | --- |
| `title`, `upper`, `lower` | `{state\|title}` | "not_home" → "Not home" |
| `round`, `round:n` | `{temp\|round:1}` | 73.46 → "73.5" |
| `percent`, `percent:n` | `{monitor_uptime_ratio_1d\|percent}` | 0.9965 → "99.7%" |
| `duration`, `duration:unit` | `{blocking.timer\|duration}` | 299 seconds → "4m 59s". A unit reads other times: `ticks` (100 ns, so 10,000,000 a second, as Jellyfin and Emby count), `ms`, `s` (the default) or `min`: `{NowPlayingItem.RunTimeTicks\|duration:ticks}` is 70,800,000,000 → "1h 58m". |
| `timecode`, `timecode:unit` | `{PlayState.PositionTicks\|timecode:ticks}` | A player's clock, rounded down to the second: "1:42:10", "42:05" under an hour, "0:07". Takes the same units as `duration`. A negative time reads "0:00", and text that isn't a number passes through, as with `duration`. |
| `pad:n` | `S{ParentIndexNumber\|pad:2}E{IndexNumber\|pad:2}` | A whole number zero-padded to n digits (1–4): 2 and 5 → "S02E05". Longer numbers aren't cut; anything that isn't a whole number passes through unchanged. |
| `clip:N` | `{overview\|clip:80}` | Shorten text to at most N characters (1 to 500), including the ellipsis. Prefer a word boundary in the last 20 characters. Trim trailing spaces and punctuation. Shorter text stays unchanged. |
| `until` | `{blocking.timer\|until}` | The clock time that many seconds from now: "2:00 PM" |
| `from_now` | `{choice\|from_now}` | The moment that many seconds from now, in ISO 8601 UTC: 3600 → "2026-11-17T21:41:05Z". For a button's request, such as a silence's end; see [Buttons](https://legatobar.com/docs/buttons.md). |
| `month` | `{start_date\|month}` | The month of a date, short: `2026-10-01` → "Oct". |
| `month_year` | `{published\|month_year}` | The month and year of a date: `2026-11-18` → "Nov 2026". For a date that should read the same next year, such as a release's. |
| `date` | `{Date\|date}` | A date, short: `2026-10-31` → "Oct 31", with no "Today" and no year. For columns by day across a month, where every column needs a label of its own. |
| `compass` | `{wind_deg\|compass}` | Degrees as one of the eight points of the compass: 200 → "S", 315 → "NW". |
| `hour` | `{dt\|hour}` | "Now" for this hour, then the hour short: "11P", "1A", "12P". For a forecast's columns. |
| `hour:plain` | `{dt\|hour:plain}` | The hour short, this one too: "12P" where `hour` says "Now". For a chart of the last 24 hours, whose last column is still filling. |
| `clock`, `clock_hour` | `{time\|clock}` | A moment's time of day as this Mac's clock shows it: "6:12 PM" (or "18:12"), and with `clock_hour` just its hour, "6 PM". For a chart's labels, since unlike `ago` they don't change as time passes: `{time\|weekday} {time\|clock_hour}` is "Tue 2 PM". |
| `bytes` | `{usage\|bytes}` | A count of bytes in the unit that suits it, 1,024 to the next and written as people say sizes: 14,195,561 → "13.5 MB", 462,773,288,960 → "431 GB", 4,617,948,836,659 → "4.2 TB". One decimal under 100, none from 100. Text that isn't a number passes through. |
| `plain` | `{__search_hit__.highlights\|plain}` | An HTML snippet as words, such as a search hit's excerpt: `Home <b>insurance</b>,` → "Home insurance,". Tags that mark words (`b`, `i`, `em`, `span`, `mark` and the like) go with no space; any other tag, and each run of spaces and line breaks, becomes one space. `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&apos;`, `&nbsp;` and numeric entities are decoded once, after the tags are gone. Nothing is drawn or loaded. |
| `verbatim` | `{title\|clip:160\|verbatim}` | Text exactly as the service sent it, for a field that takes inline formatting: a list item's text or a text card's body. `__init__()` keeps its underscores, and `[docs](https://…)` stays as words, with no link. It puts a backslash before each ASCII punctuation mark, which the formatting hides; anywhere else the backslashes show. It goes last, after `clip` or any other filter. |
| `ceil` | `legato://page/pihole-queries?at={time\|ceil}` | A number rounded up to a whole one: a moment with fractions of a second, `1795624370.4`, as the Unix second `1795624371`, so a link's "up to this second" includes it. |
| `ms` | `{reply.time\|ms}` | Seconds read as a reply time: `0.00012` is `0.1 ms`, `0.0123` is `12 ms` and `1.24` is `1.2 s`. Under a tenth of a millisecond it's `<0.1 ms`. |
| `host` | `{address\|host}` | An address's host alone: `https://raw.example.com/lists/pro.txt` is `raw.example.com`. |
| `file` | `{address\|file}` | The last part of an address's path: `pro.txt`. With `host`, a name for a list that has none of its own. |
| `raw` | `https://my.lunchmoney.app/transactions?transaction_id={id\|raw}` | A number exactly as the service sent it, with no thousands separators: 2528490123 stays `2528490123`, not "2,528,490,123". For an id in a link. Text passes through unchanged. |
| `origin` | `{monitor_url\|origin}` | An address's scheme, host and port, without its path: `https://glance.example.com/api/healthz` → `https://glance.example.com`. For a link to the app a health check watches. |
| `weekday` | `{dt\|weekday}` | "Today", then the short weekday: "Thu". For a forecast's rows. |
| `day` | `{date_expected\|day}` | The day a date falls on, as you'd say it: "Today", "Tomorrow", "Yesterday", then "Sat, Oct 31" (with the year when it isn't this one). For when something is due or expected. |
| `ago` | `{published\|ago}` | How long ago an ISO 8601 date or Unix time was: "now", "5m ago", "2h ago", "3d ago", then the date ("Oct 12"). A date with no time, like `2026-10-12`, counts from that day's midnight on the Mac. Worked out when the source answers. |
| `in` | `{dt\|in}` | How far ahead a moment is: "now", "in 12m", "in 2h", "in 3d", then the date after a week. Past moments say "now". Reads the same dates as `ago`. Worked out when the source answers. |

`ago`, `month`, `month_year`, `day`, `weekday` and `hour` read Unix time (seconds, or milliseconds as Tesla sends them), ISO 8601, a plain date (`2026-10-31`) or a date and time with no zone (`2026-10-31 14:30:00`, as Parcel sends them). The last two are read as the Mac's own time, so a date isn't the evening before when you're west of Greenwich.

Numbers are formatted for reading: `104628` becomes "104,628".

