Format ChatGPT and Claude API JSON Responses Instantly
May 31, 2026 · 7 min read · Open JSON Formatter →
If you're building with AI APIs — OpenAI's GPT-4o, Anthropic's Claude, Google's Gemini, or any other LLM provider — you're dealing with JSON constantly. Every API response, every function call result, every tool use output arrives as a JSON object. And when something goes wrong, you need to read that JSON fast.
The problem: AI API responses are often deeply nested, minified, or contain escaped strings that make them nearly impossible to read at a glance. This post shows you exactly 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 structurally different:
- Deep nesting: Response → choices → message → content → tool_calls → function → arguments (which is itself JSON-encoded as a string)
- Escaped strings inside JSON: The
contentfield in structured outputs often contains JSON-as-a-string, requiring double-parsing - Streaming chunks: Server-sent events produce partial JSON fragments that need to be assembled
- Tool use complexity: Function calling / tool use adds another layer of nested structure
The OpenAI Chat Completions Response Structure
Here's what a raw response from the OpenAI Chat Completions API looks like when 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 becomes immediately readable:
{
"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 but equally nested structure, especially when tool use is involved:
{
"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
One of the trickiest patterns in AI API debugging is function calling results, where the arguments field contains 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 is actually JSON. To read it, you need to 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 good JSON formatter with tree view makes this double-parsing pattern visible immediately.
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.
Pasting this into an online JSON formatter that sends data to a server — even a trusted one — means your data leaves your control. This is particularly concerning when:
- You're debugging production responses containing real user data
- Your system prompt contains proprietary business logic
- Tool call arguments contain PII (names, emails, addresses)
- You're 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. You can verify this by opening your browser's DevTools → Network tab and watching zero 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 hit Format. The tree view lets you navigate 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. When using these features, formatting becomes even more important because the response is 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
We recommend this toolset for AI developers who care about keeping data local:
- Format responses: ToolPry JSON Formatter — 100% client-side
- Decode JWT tokens: ToolPry Base64 decoder (JWT = Base64URL header + payload)
- Verify model downloads: ToolPry Hash Generator — SHA-256 in browser
- Generate test IDs: ToolPry UUID Generator — for idempotency tokens
- Test regex on AI output: ToolPry Regex Tester — parse structured text
All tools run 100% in your browser. No accounts, no API keys, no data uploaded. GDPR-compliant by architecture, not by policy.
Format your AI API responses now →
Paste any JSON response from OpenAI, Claude, or Gemini. Format, validate, and navigate the tree — 100% in your browser. No data leaves your machine.
Open JSON FormatterRelated: JSON to CSV Conversion Guide · Verify File Checksums · Base64 vs. Encryption