# Read surfacedd's JSON output in scripts, CI and AI agents

> When its output isn't a terminal, the surfacedd command prints one JSON document per command, in the versioned format surfacedd.cli/v1. Success has ok: true, a context (brand, range) and data, the matching MCP tool's result. Failure has ok: false and an error with a code, a message and the exit code.

Source: https://surfacedd.com/docs/cli/json-output · Updated 2026-11-19

Scripts, CI jobs and AI agents should read the JSON, not the tables. You rarely need to ask for it: the command prints JSON whenever stdout isn't a terminal, which covers pipes, files, CI logs and an agent's shell. `--json` forces it in a terminal; `--human` forces tables anywhere. Progress lines, notes and the confirmation question go to stderr, so stdout holds only the document. 

## The success envelope

```json
{
  "schema": "surfacedd.cli/v1",
  "command": "visibility",
  "ok": true,
  "context": { "brand": { "id": "01a1f315-4dca-…", "name": "Tallyfox", "kind": "brand" }, "range": "30d" },
  "data": { "…": "the MCP tool's answer, unchanged" }
}
```

| Field | Meaning |
|---|---|
| `schema` | Always `surfacedd.cli/v1` for this version of the format |
| `command` | The command's fixed words, such as `visibility`, `answers search`, `gsc top` or `report run`. Never the arguments, so you can branch on it safely |
| `ok` | `true` |
| `context.brand` | The brand the command used (`id`, `name`, `kind` of `brand` or `person`), or `null` when the command has none |
| `context.range` | The period applied, such as `7d` or `2026-10-01..2026-10-31`, or `null` |
| `data` | For read commands, the matching MCP tool's result, field for field |

Keys come out in alphabetical order, which keeps diffs between two runs small. 

Because read commands reuse the MCP tools, the [MCP tool reference](/docs/mcp/tool-reference) documents every `data` shape. The [command reference](/docs/cli/commands) maps each command to its tool. 

## The error envelope

```json
{
  "schema": "surfacedd.cli/v1",
  "command": "report run",
  "ok": false,
  "error": { "code": "budget", "message": "The estimate ($4.18) is above --max-usd ($2.00). Nothing was spent.",
             "exit_code": 4, "data": { "estimate": { "p50_usd": 4.1823, "…": "…" }, "max_usd": 2.0 } }
}
```

`error.exit_code` repeats the process [exit code](/docs/cli/exit-codes), so a script that only has the file still knows what happened. `error.data` appears when there's something useful to act on, such as the estimate behind a refusal. 

| `error.code` | Typical cause |
|---|---|
| `usage` | Unknown command or option, bad `--range`, missing argument, an API key passed as a flag |
| `licence` | This computer isn't activated, or a job was started on a read-only licence |
| `budget` | The estimate is over `--max-usd` or a hard budget cap, or a run stopped at either part-way (see `data.limit`) |
| `confirmation` | A paid run without `--yes` outside a terminal, or "no" at the prompt |
| `threshold` | `agent-readiness check` scored under `--fail-under`. Stdout still carries the success document; see the note below |
| `not_found` | The brand, report, answer, product or person doesn't exist |
| `sample` | A paid or changing command on the sample workspace |
| `busy` | Another `surfacedd` job is running |
| `keys` | A run needs an API key that isn't saved |
| `database` | The workspace file is missing or unreadable |
| `app`, `doctor`, `mcp`, `error` | Problems talking to the app, a failed doctor check, the MCP server, anything else |

## Three exceptions to know

1. **A failing agent readiness threshold is still a success document.** `agent-readiness check --fail-under N` prints `ok: true` with `data.passed: false`, `data.fail_under` and the full result, then exits 5. Read the scores and failing rules from `data` either way.
2. **`doctor` with a failing check** prints its report (`data.ok: false`) and exits 1.
3. **`export` without `--out`** prints the export itself, not an envelope: a JSON file in the app's export format (`format: "surfacedd-export"`, `version: 1`), CSV or NDJSON. `surfacedd mcp` speaks MCP, not this format.

## Examples with jq

```bash
# Overall visibility for the last 7 days, as a number
surfacedd visibility --range 7d | jq '.data.visibility.rate.pct'

# Competitors and their share of voice, tab-separated
surfacedd competitors --range 30d \
  | jq -r '.data.rows[] | select(.is_subject == false) | [.name, .sov_pct] | @tsv'

# Stop a script on any failure, with the message
out=$(surfacedd prompts) || { echo "$out" | jq -r '.error.message'; exit 1; }
```

We ran these paths against the sample workspace with this version of the command. Field names inside `data` follow the MCP tools; percentages are plain numbers, such as `41.9` for 41.9%. 

## The schema and versioning

The JSON Schema for the envelope is published at [surfacedd.com/schemas/cli/v1.json](https://surfacedd.com/schemas/cli/v1.json), its `$id`. Point a validator or your editor at it. 

Within v1, fields are only ever added, never renamed or removed. Write scripts that ignore fields they don't know. A breaking change would get a new `schema` value, and `surfacedd version` prints the one your command speaks:

```console
$ surfacedd version
surfacedd 0.1.0 (output surfacedd.cli/v1, database schema v9)
```

The CLI's tests keep a shape snapshot for every read command and fail when the output changes shape, so a field doesn't disappear by accident.
