Skip to content
Başlangıç Orta

Yapılandırılmış Çıktı Kullanma (JSON Schema)

Kısıtlanmış kod çözme ile Claude'u tam bir JSON schema'ya uygun veri döndürmeye zorlayın

Komut

$ "color:#7C5CFC">claude -p "Extract: 'John Smith is 32 years old'" \
    "color:#d97757">--output-format json \
    "color:#d97757">--json-schema '{"type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer"}},"required":["name","age"]}'

Yanıt

{
  "structured_output": {
    "name": "John Smith",
    "age": 32
  },
  "result": "",
  "total_cost_usd": 0.073
}

Ayrıştırma Kodu

059669">">const data = JSON.parse(output);
059669">">// Always read structured_output, NOT result
059669">">const { name, age } = data.structured_output;
console.log(059669">`${name} is ${age} years old`);

Tuzaklar

! --output-format json gerektirir — text formatı --json-schema ile boş çıktı üretir
! structured_output alanını okuyun, result alanını değil — birbirinden bağımsızdırlar

İlgili Tarifler