Skip to content

JSON Output

All commands support the global --json flag.

Use JSON mode for automation, scripts, and CI/CD pipelines.

Terminal window
# List pull requests as JSON
bb pr list --json
# Disable color formatting and return JSON
bb repo view --json --no-color

The CLI uses a small number of consistent output patterns. Understanding these patterns lets you predict the JSON shape of any command.

Used by: pr list, repo list, pr comments list, pr activity, pr reviewers list, pr checks

Returns an envelope with metadata and a named array:

{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"state": "OPEN",
"filters": {},
"count": 2,
"pullRequests": [...]
}

Common envelope fields:

FieldTypePresent in
workspacestringPR and repo collections
repoSlugstringPR collections
countnumberAll collections
statestringpr list
filtersobjectpr list (when --mine is used), pr activity

Collection key names:

CommandArray key
pr listpullRequests
repo listrepositories
pr comments listcomments
pr activityactivities
pr reviewers listreviewers
pr checksstatuses (inside a summary + statuses structure)
{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"state": "OPEN",
"count": 2,
"pullRequests": [
{
"id": 42,
"title": "Add feature",
"state": "OPEN",
"draft": false,
"author": { "display_name": "Alice", "nickname": "alice" },
"source": { "branch": { "name": "feature/add-feature" } },
"destination": { "branch": { "name": "main" } },
"created_on": "2026-01-15T10:00:00.000000+00:00",
"updated_on": "2026-01-16T14:30:00.000000+00:00",
"links": { "html": { "href": "https://bitbucket.org/myworkspace/myrepo/pull-requests/42" } }
}
]
}
{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"state": "OPEN",
"filters": { "mine": true },
"count": 1,
"pullRequests": [...]
}
{
"pullRequestId": 42,
"workspace": "myworkspace",
"repoSlug": "myrepo",
"summary": { "successful": 2, "failed": 0, "pending": 1 },
"statuses": [...]
}

Pattern 2: Resource (View/Create Commands)

Section titled “Pattern 2: Resource (View/Create Commands)”

Used by: pr view, repo view, pr create, pr edit

Returns the raw Bitbucket API resource object directly, with no envelope:

{
"type": "pullrequest",
"id": 42,
"title": "Add feature",
"state": "OPEN",
"author": {...},
"source": {...},
"destination": {...},
"participants": [...],
"links": {...}
}

Pattern 3: Action (Approve/Merge/Decline Commands)

Section titled “Pattern 3: Action (Approve/Merge/Decline Commands)”

Used by: pr approve, pr decline, pr merge, pr ready, pr comments add/edit/delete, pr reviewers add/remove, auth login, auth logout

Returns a success indicator plus resource identifiers:

{
"success": true,
"pullRequestId": 42
}

Some action commands include the full resource in the response:

{
"success": true,
"pullRequestId": 42,
"pullRequest": {...}
}

Used by: pr diff (with --stat, --web, --name-only, or default diff mode)

Returns context metadata plus mode-specific data:

{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"pullRequestId": 42,
"mode": "stat",
"filesChanged": 3,
"totalAdditions": 27,
"totalDeletions": 11,
"files": [
{ "path": "src/index.ts", "additions": 10, "deletions": 3 }
]
}
{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"pullRequestId": 42,
"mode": "name-only",
"files": ["src/index.ts", "src/utils.ts"]
}
{
"workspace": "myworkspace",
"repoSlug": "myrepo",
"pullRequestId": 42,
"mode": "web",
"url": "https://bitbucket.org/myworkspace/myrepo/pull-requests/42/diff"
}

These commands have unique output shapes:

{
"authenticated": true,
"user": {
"username": "myuser",
"displayName": "My Name",
"accountId": "70121:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
{
"token": "base64-encoded-username:apiToken"
}
{
"configPath": "/Users/you/.config/bb/config.json",
"config": {
"username": "myuser",
"apiToken": "********",
"defaultWorkspace": "myworkspace",
"skipVersionCheck": false
}
}
{
"key": "defaultWorkspace",
"value": "myworkspace"
}

Terminal window
# Print PR titles
bb pr list --json | jq -r '.pullRequests[].title'
# Count PRs
bb pr list --json | jq '.count'
# Get repository names
bb repo list --json | jq -r '.repositories[].full_name'
# Extract diff file paths
bb pr diff 42 --stat --json | jq -r '.files[].path'
# Get PR URLs
bb pr list --json | jq -r '.pullRequests[].links.html.href'
# Check auth status
bb auth status --json | jq '.authenticated'
  • Prefer --json in scripts rather than parsing text output.
  • Do not rely on text formatting symbols (, table separators, colors).
  • If you need stable fields, prefer command-specific documented keys (pullRequests, repositories, files, success).
  • pr list returns lightweight PR objects. Use pr view <id> for full details including participants and reviewers.

When a command fails, the CLI exits non-zero.

  • In normal mode, errors are plain text on stderr.
  • In --json mode, errors are compact JSON objects on stderr.

Example:

Terminal window
bb config get invalidKey --json 2>error.json
cat error.json
# {"name":"BBError","code":4003,"message":"Unknown config key 'invalidKey'. Valid keys: username, defaultWorkspace, skipVersionCheck, versionCheckInterval","context":{"key":"invalidKey"}}

Error JSON fields:

FieldTypeDescription
namestringError class name (always BBError)
codenumberNumeric error code
messagestringHuman-readable message
contextobjectOptional structured metadata

In automation, always check the process exit code before parsing stdout JSON.