docs/pkg/jsonextract.md
JSON extraction
pkg/jsonextract exposes
Extract(text string) (json.RawMessage, error) for JSON in model responses.
Auto-title and TUI snooze share extraction, but own their schemas and validation.
Selection order:
- Accept the entire trimmed response if it is valid JSON.
- Otherwise select the first
jsonMarkdown fence, case-insensitively. - Without a
jsonfence, select the first unlabelled fence. - Without either matching fence, locate the first
{or[and use Go's JSON decoder to read one complete object or array, tolerating surrounding prose. Numbers, quoted words and punctuation in prose do not select scalar values.
Fences support CRLF. A selected fence must close and contain only valid JSON; trailing garbage within it is an error. Invalid selected blocks or candidates are not skipped for a later valid value. Extraction preserves objects, arrays and whole-input or fenced scalars, including duplicate object keys, so callers can enforce their own shape and field rules. In particular, it never unwraps an object inside an array.
Durable tests live in jsonextract_test.go.
Use the focused package recipe in the test guide.