# JSON output (/docs/diagnostics/json)

Each line is one object with `"schema": 1` and a `kind`. A command writes zero or more
`diagnostic` lines and ends with one `result` line.

```json
{"schema":1,"kind":"diagnostic","severity":"error","code":"M0002","message":"undefined: fmt.Printn",
 "span":{"file":"/src/app/main.go","line":15,"col":6,"endLine":15,"endCol":12},
 "help":["a func with a similar name exists: fmt.Println"],
 "fixes":[{"title":"use fmt.Println","edits":[{"file":"/src/app/main.go",
   "span":{"file":"/src/app/main.go","line":15,"col":6,"endLine":15,"endCol":12},"newText":"Println"}]}],
 "context":{"function":"func main()","lines":[{"line":15,"text":"\tfmt.Printn(\"x\")"}]},
 "explain":"marmot explain M0002"}
{"schema":1,"kind":"result","command":"build","ok":false,"errors":1,"warnings":0,"durationMs":310,"exitCode":1}
```

New fields may be added within schema 1; parsers must ignore fields they do not know.

## diagnostic [#diagnostic]

| Field | Meaning |
| --- | --- |
| `severity` | `error`, `warning` or `note`. |
| `label` | What is wrong at the primary span, readable on its own. |
| `code` | Stable code, `M0000` when there is no more specific one. See [Error codes](/docs/diagnostics/codes). |
| `message` | The message, as in plain mode. |
| `span` | Primary location. Lines and columns are 1-based, columns count bytes, `endCol` is exclusive. Absent location: `file` is empty. |
| `labels` | Secondary spans, each `{span, text}`. |
| `notes`, `help` | Lists of strings. |
| `fixes` | Suggested fixes, each `{title, applicability, edits}`; an edit is `{file, span, newText}` and replaces the span (an empty span inserts). `applicability` is `machine-applicable` (safe to apply unseen), `maybe-incorrect` (likely, check it) or `has-placeholders` (never apply as is). Applying every edit of one fix resolves the diagnostic. |
| `related` | Other locations, each `{span, message}`, for example the declaration of a called function. |
| `context` | What you would open the file for: `function` (enclosing signature), `lines` (source around the span, `{line, text}`), `types` (one line definitions of the types the message names). |
| `bundle` | Internal compiler errors only: a directory with the inputs for a bug report. |
| `rendered` | The human form without color, exactly what a person would see. |
| `fullMessage` | Present when `message` was shortened (long type names elided). |
| `explain` | The command that describes the code. |

In JSON mode all errors are listed (no cap), duplicates removed, in a stable order.

## result [#result]

`command`, `ok`, `errors`, `warnings`, `output` (the file written, on success), `durationMs`,
`exitCode`.

## Other commands [#other-commands]

Other commands use the same envelope (`schema`, `kind`) with their own kinds:

| Command | Kinds |
| --- | --- |
| `marmot test -json` | `test` per test, `diagnostic` per failure, `result` |
| `marmot fix -json` | `fix` per applied fix (`file`, `code`, `title`, `line`), then `diagnostic` and `result` |
| `marmot fmt -json` | `format` per changed file (`file`, `written`), `result` |
| `marmot generate -json` | `generate` per directive (`command`, `cached`, `outputs`), `result` |
| `marmot watch -json` | `watch` events (`build`, `done`) around each round's own output |
| `marmot size -json` | one `size` object: `sections`, `packages`, `functions`; `-why` gives `why` with `chain` |
| `marmot bench -json` | `bench` per benchmark and unit, with the summaries, `delta` and `p` |
| `marmot prof -json` | one `profile` object: `functions`, `lines`, and `tree` with `-tree` |
| `marmot doctor -json` | `doctor` per check (`check`, `status`, `detail`, `fix`), `result` |
| `marmot check -json` | `diagnostic` per finding with `check` and `analyzer`, `check` per check, `result` |
| `marmot explain -json CODE` | `{code, title, text, wrong, right, fix}` on stdout |