JSON Output
All commands support the global --json flag.
Use JSON mode for automation, scripts, and CI/CD pipelines.
Quick Usage
Section titled “Quick Usage”# List pull requests as JSONbb pr list --json
# Disable color formatting and return JSONbb repo view --json --no-colorOutput Model
Section titled “Output Model”JSON output is normalized, but not every command returns the same shape.
- List commands return an object envelope with metadata and an array.
- Read/create/update commands usually return a resource object (or resource plus metadata).
- Action commands usually return
success: trueplus identifiers.
Typical top-level metadata fields include:
workspacerepoSlugpullRequestIdcount
Common Examples
Section titled “Common Examples”bb pr list --json
Section titled “bb pr list --json”{ "workspace": "myworkspace", "repoSlug": "myrepo", "state": "OPEN", "count": 2, "pullRequests": [ { "id": 42, "title": "Add feature", "state": "OPEN" } ]}bb repo list --json
Section titled “bb repo list --json”{ "workspace": "myworkspace", "count": 1, "repositories": [ { "full_name": "myworkspace/myrepo", "is_private": true } ]}bb pr diff 42 --stat --json
Section titled “bb pr diff 42 --stat --json”{ "workspace": "myworkspace", "repoSlug": "myrepo", "pullRequestId": 42, "mode": "stat", "filesChanged": 3, "totalAdditions": 27, "totalDeletions": 11, "files": [ { "path": "src/index.ts", "additions": 10, "deletions": 3 } ]}bb pr diff 42 --web --json
Section titled “bb pr diff 42 --web --json”{ "workspace": "myworkspace", "repoSlug": "myrepo", "pullRequestId": 42, "mode": "web", "url": "https://bitbucket.org/myworkspace/myrepo/pull-requests/42/diff"}bb auth token --json
Section titled “bb auth token --json”{ "token": "base64-encoded-credentials"}jq Examples
Section titled “jq Examples”# Print PR titlesbb pr list --json | jq -r '.pullRequests[].title'
# Count PRsbb pr list --json | jq '.count'
# Get repository namesbb repo list --json | jq -r '.repositories[].full_name'
# Extract diff file pathsbb pr diff 42 --stat --json | jq -r '.files[].path'Scripting Notes
Section titled “Scripting Notes”- Prefer
--jsonin 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).
Errors
Section titled “Errors”When a command fails, the CLI exits non-zero.
- In normal mode, errors are plain text on stderr.
- In
--jsonmode, errors are compact JSON objects on stderr.
Example:
bb config get invalidKey --json 2>error.jsoncat error.json# {"name":"BBError","code":4003,"message":"Unknown config key 'invalidKey'. Valid keys: username, defaultWorkspace, skipVersionCheck, versionCheckInterval","context":{"key":"invalidKey"}}In automation, always check the process exit code before parsing stdout JSON.