Drift CLIOperate Drift with explicit commands

JSON output reference

Use this reference when implementing a parser for Drift CLI output. JSON mode uses a versioned success envelope on standard output and a versioned error envelope on standard error.

Selection and destination

JSON mode is selected by --json, DRIFT_OUTPUT=json, or a configuration value of json. The command-line flag has the highest precedence.

OutcomeDestinationExit status
SuccessStandard output0
Runtime errorStandard errorNonzero
Parse errorStandard error2

Success envelope

{
  "schemaVersion": 1,
  "command": "key.list",
  "data": {
    "keys": []
  }
}
FieldTypeContract
schemaVersionnumberCurrently 1; consumers must reject unknown versions.
commandstringStable identifier for the completed command.
dataobjectCommand-specific success payload.

Create and rotate success payloads include the returned one-time secret at data.secret. Other success payloads do not expose credentials.

Error envelope

{
  "schemaVersion": 1,
  "error": {
    "kind": "api",
    "message": "Drift returned HTTP 403: Admin scope required",
    "httpStatus": 403,
    "code": "forbidden"
  }
}
FieldRequiredContract
schemaVersionYesCurrently 1.
error.kindYesStable coarse failure category.
error.messageYesSafe diagnostic text; not a control-flow contract.
error.httpStatusNoDrift HTTP status when the failure has a server response.
error.codeNoDrift error code when the response supplies one.

Error output never includes the authorization header, bearer key, or a one-time secret returned by a successful mutation.

Compatibility rules

  • Consumers should branch on schemaVersion, command, exit status, error.kind, and error.code.
  • Consumers must not parse human output or depend on error.message wording.
  • New optional fields may appear within schema version 1.
  • Removing or changing the meaning of an existing field requires a new schema version.
  • Cursors and server-owned identifiers are opaque strings.

See Use JSON output in automation for a task-oriented example.