Scripting with JSON
Every command accepts a global --output flag. The default is table (human-readable); json emits raw, pretty-printed JSON suitable for scripting.
bitbucket repo list myworkspace --output jsonHow JSON mode behaves
Section titled “How JSON mode behaves”- List commands print the array of items (an empty result is
[]), with no “more available” notices. - View commands print the single entity.
- Mutations print the returned entity, or
{"ok": true}when the API returns no body. - Errors go to stderr as text, so stdout always contains valid JSON (or nothing).
- Confirmation prompts still run for destructive commands; pass
--yesfor non-interactive use. - Raw-output commands —
pr diff,pr patch,commit diff,file cat— emit their raw text unchanged so they stay pipe-friendly.
Examples
Section titled “Examples”Get the clone URL of every repository in a workspace:
bitbucket repo list myworkspace --output json \ | jq -r '.[].links.clone[] | select(.name=="ssh") | .href'List open pull request titles:
bitbucket pr list myworkspace/myrepo --state open --output json \ | jq -r '.[].title'Fail a CI step when a PR has unresolved tasks:
count=$(bitbucket pr task list myworkspace/myrepo 42 --output json \ | jq '[.[] | select(.state=="UNRESOLVED")] | length')[ "$count" -eq 0 ] || { echo "$count unresolved task(s)"; exit 1; }