← Blog

Format ChatGPT and Claude API JSON Responses Instantly

May 25, 2026 · 7 min read · Open JSON Formatter →

If you build with AI APIs (OpenAI's GPT-4o, Anthropic's Claude, Google's Gemini or any other LLM provider), you deal with JSON all the time. Every API response, function call result and tool use output arrives as a JSON object. When something goes wrong, you need to read that JSON fast.

AI API responses are often deeply nested, minified, or full of escaped strings that make them hard to read at a glance. This post shows how to format and debug them efficiently.

Why AI API Responses Are Harder to Read Than Regular JSON

A typical REST API might return a flat object with 5–10 keys. AI API responses are built differently:

  • Deep nesting: Response → choices → message → content → tool_calls → function → arguments (itself JSON encoded as a string)
  • Escaped strings inside JSON: In structured outputs the content field often holds JSON as a string, which you have to parse twice
  • Streaming chunks: Server-sent events produce partial JSON fragments you have to assemble
  • Tool use complexity: Function calling / tool use adds another layer of nested structure

The OpenAI Chat Completions Response Structure

Here is a raw OpenAI Chat Completions response as logged to the console:

{"id":"chatcmpl-9abc123","object":"chat.completion","created":1748649600,"model":"gpt-4o","choices":[{"index":0,"message":{"role":"assistant","content":"The capital of France is Paris."},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":14,"completion_tokens":9,"total_tokens":23},"system_fingerprint":"fp_abc123"}

Formatted, it is readable at once:

{
  "id": "chatcmpl-9abc123",
  "object": "chat.completion",
  "created": 1748649600,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 9,
    "total_tokens": 23
  },
  "system_fingerprint": "fp_abc123"
}

The Anthropic Claude API Response Structure

Claude's API uses a different structure that is just as nested, especially with tool use:

{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_01A09q90qw90lq917835lq9",
      "name": "get_weather",
      "input": {
        "location": "San Francisco, CA",
        "unit": "celsius"
      }
    }
  ],
  "model": "claude-opus-4-6-20251101",
  "stop_reason": "tool_use",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 68,
    "output_tokens": 56
  }
}

Function Calling: JSON Inside JSON

Function calling results are tricky to debug because the arguments field holds JSON encoded as a string:

{
  "tool_calls": [
    {
      "id": "call_abc123",
      "type": "function",
      "function": {
        "name": "search_products",
        "arguments": "{\"query\":\"bluetooth headphones\",\"max_price\":100,\"category\":\"electronics\"}"
      }
    }
  ]
}

The arguments field looks like a string, but its content is JSON. To read it, parse it separately. In JavaScript:

const toolCall = response.choices[0].message.tool_calls[0];
const args = JSON.parse(toolCall.function.arguments);
// { query: "bluetooth headphones", max_price: 100, category: "electronics" }

A JSON formatter with a tree view makes this double-parsing pattern visible right away.

Why Privacy Matters When Formatting AI API Responses

AI API responses often contain sensitive information: user messages, proprietary system prompts, customer data in function call arguments, and internal business logic in tool responses.

Paste this into an online JSON formatter that sends data to a server, even a trusted one, and your data leaves your control. That is a particular concern when:

  • You are debugging production responses that contain real user data
  • Your system prompt contains proprietary business logic
  • Tool call arguments contain PII (names, emails, addresses)
  • You are subject to GDPR or other data protection regulations

The ToolPry JSON Formatter processes everything in your browser using native JSON.parse() and JSON.stringify(). No data is transmitted. To check, open your browser's DevTools → Network tab and watch: no requests fire when you click Format.

Quick Formatting Workflows for AI Development

In the Terminal (during development)

# Python: pretty-print an API response
import json
response = client.messages.create(...)
print(json.dumps(response.model_dump(), indent=2))

# Node.js
console.log(JSON.stringify(response, null, 2))

# curl + jq
curl -s -X POST https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-opus-4-6","max_tokens":100,"messages":[{"role":"user","content":"Hi"}]}' \
  | jq .

In the Browser (for quick debugging)

Copy the response from your API client or console, paste it into ToolPry, and click Format. The tree view lets you move through nested structures like choices[0].message.content without counting braces.

In VS Code

Select the JSON text → Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS). For logged JSON strings, use the "JSON Tools" extension.

Structured Outputs: JSON Mode in AI APIs

OpenAI's JSON mode and Anthropic's structured output features guarantee that API responses are valid JSON. With these features, formatting matters even more, because the responses are richer and more structured:

// OpenAI JSON mode response
{
  "extracted_data": {
    "company": "Acme Corp",
    "invoice_number": "INV-2026-0531",
    "line_items": [
      { "description": "Widget A", "qty": 10, "unit_price": 9.99, "total": 99.90 },
      { "description": "Widget B", "qty": 5, "unit_price": 24.99, "total": 124.95 }
    ],
    "subtotal": 224.85,
    "tax_rate": 0.21,
    "tax_amount": 47.22,
    "total": 272.07,
    "currency": "EUR"
  }
}

The Privacy-First AI Development Stack

For AI developers who want to keep data local, we recommend this toolset:

Every tool runs 100% in your browser: no accounts, no API keys, no uploads. GDPR-compliant by architecture, not by policy.

Format your AI API responses now →

Paste any JSON response from OpenAI, Claude or Gemini. Format it, validate it and browse the tree, 100% in your browser. No data leaves your machine.

Open JSON Formatter

Related: JSON to CSV Conversion Guide · Verify File Checksums · Base64 vs. Encryption

Frequently Asked Questions

Why are AI API JSON responses harder to read than regular JSON?

AI API responses wrap the actual content inside nested objects — the generated text sits inside choices[0].message.content (OpenAI) or content[0].text (Anthropic). If the model used function calling or returned structured JSON, you get JSON embedded inside a JSON string, requiring two parse steps.

How do you extract the text content from an OpenAI API response?

Access response.choices[0].message.content for the generated text. For function calling results, parse response.choices[0].message.tool_calls[0].function.arguments — which is a JSON string that you then pass to JSON.parse() a second time.

What is JSON mode in AI APIs and when should you use it?

JSON mode (OpenAI response_format: {type: 'json_object'}, Anthropic tool use) forces the model to output valid JSON. Use it when you need structured data for programmatic processing. Without JSON mode, models may output JSON wrapped in markdown code fences that require stripping before parsing.

Why does privacy matter when formatting AI API responses in developer tools?

API responses often contain sensitive data — user PII, internal system details, proprietary logic. Using cloud-based formatting tools sends this data to third-party servers. Browser-based tools like ToolPry process everything locally in JavaScript, so your API response data never leaves your device.