$ recombobulate _
home / tips / get-validated-json-output-with-json-schema
0

Get Validated JSON Output with --json-schema

bagwaa @bagwaa · Mar 26, 2026 · Configuration
get-validated-json-output-with-json-schema

When you're building tooling around Claude Code, you often need structured output you can parse reliably. The --output-format json flag gets you JSON, but it doesn't guarantee the shape of that JSON. The --json-schema flag does.

claude -p --json-schema '{
  "type": "object",
  "properties": {
    "bugs": { "type": "array", "items": { "type": "string" } },
    "severity": { "type": "string", "enum": ["low", "medium", "high"] }
  },
  "required": ["bugs", "severity"]
}' "Review this file for bugs: src/auth.ts"

Claude will complete its normal workflow (reading files, reasoning, etc.), then return a final JSON object that matches your schema exactly. If the output doesn't validate, Claude retries until it does.

This is powerful for building automated pipelines where downstream tools expect a specific data shape:

# Extract structured metadata from a codebase
claude -p --json-schema '{
  "type": "object",
  "properties": {
    "language": { "type": "string" },
    "framework": { "type": "string" },
    "entryPoint": { "type": "string" },
    "dependencies": { "type": "array", "items": { "type": "string" } }
  }
}' "Analyse this project and extract its metadata"

The flag only works in print mode (-p), and you can combine it with --output-format json for the full structured response envelope, or use it standalone to get just the validated object.

Define the shape you need, and let Claude fill it in.


via Claude Code CLI Reference

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Switch to the Stable Update Channel with autoUpdatesChannel

The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.

bagwaa @bagwaa · 1 hour ago
0
Set Claude's Response Language with the language Setting

The language setting makes Claude respond in your preferred language by default, across every session and project.

bagwaa @bagwaa · 1 hour ago
0
Customize or Remove Claude's Git Attribution with the attribution Setting

The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.

bagwaa @bagwaa · 1 hour ago