Verified Claude Code
Force output to match your format with --json-schema
What it does
Pass a JSON Schema to a -p call; the validated object appears in the structured_output field, no hand parsing or retries.
How
claude -p "Extract the latest version from CHANGELOG" --output-format json \
--json-schema '{"type":"object","properties":{"version":{"type":"string"}},"required":["version"]}'
How much to trust this
| Applies to | ≥ 2.1.84 |
|---|---|
| Verified | Oct 17, 2026 · v2.1.296 · tested locally 本机实际运行,structured_output 返回 {'prime': 7};changelog 最早在 2.1.84 提到该参数 |
| Depends on | --json-schema-p |
| Source | https://code.claude.com/docs/en/cli-reference (official_docs) |