> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON モードを有効にする

> Serverless Inference で JSON モードを設定すると、モデルの応答を構造化された JSON 出力として取得でき、解析が容易になります。

JSON モードは、任意形式のテキストを処理せずに、モデルの応答をプログラムで解析したい場合に便利です。JSON モードを有効にすると、モデルは有効な JSON 形式で応答を返すようになるため、下流のコードで出力を扱いやすくなります。ただし、応答のスキーマが毎回同じであることや、特定の構造に従うことは保証されません。一貫した構造の JSON 応答が必要な場合は、可能な限り[構造化出力](/ja/products/inference/serverless/response-settings/structured-output)を使用することをお勧めします。

JSON モードを有効にするには、リクエストの `response_format` で JSON モードを指定します。

<Tabs>
  <Tab title="Python">
    ```python theme={"system"}
    import json
    import openai

    client = openai.OpenAI(
        base_url='https://api.inference.wandb.ai/v1',
        api_key="[YOUR-API-KEY]",  # APIキーは https://forge.coreweave.com/settings で作成できます
    )

    response = client.chat.completions.create(
        model="openai/gpt-oss-20b",
        messages=[
            {"role": "system", "content": "You are a helpful assistant that outputs JSON."},
            {"role": "user", "content": "Give me a list of three fruits with their colors."},
        ],
        response_format={"type": "json_object"}  # JSON モードを有効にします
    )

    content = response.choices[0].message.content
    parsed = json.loads(content)
    print(parsed)
    ```
  </Tab>

  <Tab title="Bash">
    ```bash theme={"system"}
    curl https://api.inference.wandb.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer [YOUR-API-KEY]" \
      -d '{
        "model": "openai/gpt-oss-20b",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant that outputs JSON."},
            {"role": "user", "content": "Give me a list of three fruits with their colors."},
        ],
        "response_format": {"type": "json_object"}
      }'
    ```
  </Tab>
</Tabs>
