Magic Tools
AI TutorialsBy CooconApril 22, 2026270 views4 min read

How to Use ChatGPT to Format and Validate JSON (2025)

You just got a blob of JSON from an API response and it looks like this: {"user":{"id":1,"name":"Alice","orders":[{"id":101,"items":["book","pen"],"total":29.99}]}}. One line, no spaces, completely unreadable. Or worse — your app is crashing because of a JSON parse error and you have no idea where.

ChatGPT can fix both problems in seconds.


Step 1: Format Compressed JSON

Paste your minified JSON into ChatGPT with a simple prompt. It will return a properly indented, human-readable version instantly.

Prompt template:

Format this JSON with proper indentation so it's easy to read:

[paste your JSON here]

Example input:

{"user":{"id":1,"name":"Alice","orders":[{"id":101,"items":["book","pen"],"total":29.99}]}}

What you get back:

{
  "user": {
    "id": 1,
    "name": "Alice",
    "orders": [
      {
        "id": 101,
        "items": ["book", "pen"],
        "total": 29.99
      }
    ]
  }
}

Clean, readable, done.


Step 2: Find and Fix Errors

Got a JSON parse error? ChatGPT is surprisingly good at spotting the exact problem.

Common JSON mistakes include:

  • Trailing commas (valid in JS objects, illegal in JSON)
  • Single quotes instead of double quotes
  • Missing closing brackets or braces
  • Unquoted keys

Prompt template:

This JSON has an error. Find the problem, explain what's wrong, and give me the corrected version:

[paste your broken JSON here]

ChatGPT will tell you the exact problem and hand you the fixed version.

This beats staring at error messages like Unexpected token in JSON at position 10 and trying to count characters manually.


Step 3: Understand the Structure

Sometimes you get a deeply nested JSON from an unfamiliar API and you need to know what's actually in it before writing code against it.

Prompt template:

Explain the structure of this JSON to me. Describe each field and what it likely represents. Keep it brief and practical:

[paste your JSON here]

This is useful when you're integrating a third-party API and the documentation is bad (or nonexistent). ChatGPT will walk through each key, tell you what the data types are, and flag anything that looks unusual.


Three Ready-to-Copy Prompts

Format JSON:

Format this JSON with proper indentation so it's easy to read:
[your JSON]

Find and fix errors:

This JSON has an error. Find the problem, explain what's wrong, and give me the corrected version:
[your JSON]

Explain the structure:

Explain the structure of this JSON to me. Describe each field and what it likely represents. Keep it brief and practical:
[your JSON]

FAQ

Can ChatGPT handle very large JSON files?

There's a context window limit. For most everyday API responses and config files you'll be fine. If you're dealing with a JSON file that's 50MB of data exports, ChatGPT isn't the right tool — use a local formatter like jq or a dedicated tool instead.

Is it safe to paste my JSON into ChatGPT?

It depends on what's in it. If the JSON contains API keys, passwords, or personal user data — don't paste it. Strip out the sensitive values first and replace them with placeholders. The structure is what matters, not the actual data.

What if ChatGPT gives me back invalid JSON?

It happens occasionally with complex nested structures. Always validate the output before using it. You can paste it back into ChatGPT with the prompt: "Is this valid JSON? If not, fix it."

Does ChatGPT understand JSON Schema?

Yes. You can paste a JSON Schema along with a sample JSON object and ask ChatGPT to validate whether the object matches the schema. It's useful for catching obvious mismatches — like a required field that's missing or a value that's the wrong type.

Can I use ChatGPT to convert JSON to other formats?

Absolutely. You can ask it to convert JSON to CSV, YAML, a Markdown table, or SQL INSERT statements. Just be specific: "Convert this JSON array to a CSV table with headers matching the object keys."


Want Something Faster?

For quick, no-fuss formatting and validation without opening a chat, try MagicTools JSON Formatter. Paste your JSON, get instant formatting and error highlighting — no prompts needed. It's handy when you just need to clean up a response fast and get back to work.

Related Articles

Blocking rm -rf in Claude Code: A Deny Rule Stopped 14 Deletes in Two Weeks, 7 Other Spellings Still Get Through, and a Hook That Closes the Gap

To keep Claude Code from deleting things by accident, I added a deny rule, Bash(rm -rf *), to my global settings. Across my sessions from October 7 to 21 it blocked 14 deletes. After each denial the model picked a new directory name 8 times and dropped the delete 6 times. It never tried another spelling. Then I replayed 22 delete commands verbatim against Claude Code 2.1.285 through a stub. rm -fr, rm -r -f, rm -Rf and rm -r deleted the directory in manual, auto and bypass mode alike. /bin/rm, find -delete and bash -c deleted it in manual and bypass mode. In auto mode, rm -fr inside the working directory skips the classifier because it 'would be allowed in acceptEdits mode'. A second, built-in dangerous-rm check fires on targets like $D/*, even in bypass mode, but loses track of a variable assignment when a heredoc comes earlier in the same command. The post ends with a PreToolUse hook that blocks every recursive spelling in all three modes and tells the model what to do instead.

claude-codehooks+5
pitfallsOct 21, 20268 min
208

The Self-Reinforcing Flywheel Is Harder Than It Looks: 40 Days of an LLM Auto-Tuning Loop

We ran an 'LLM proposes, code decides' auto-tuning loop on a daily WeChat newsletter for 40 days: 18 versions, 8 rollbacks. Three of those rollbacks overturned decisions a human had made, and one version whose knobs were identical to its parent still got rolled back. Using our real numbers, telling apart a 20% difference needs about 25,000 reads per version. At 60 reads a day, that is more than 400 days. This postmortem covers five reasons the flywheel never turned, and what actually moved the numbers.

wechatpostmortem+4
pitfallsOct 21, 20268 min
133

Dev Breakfast · 2026-10-21

Today's headline: A single "bonsoir, Elliot" makes the model leak its .env: a backdoor for under $50. Plus 4 more: DeepSeek open-sources its inference engine: V4.1 Flash only, and KV cache still missing; TorchTPU goes open source: PyTorch models can run directly on TPU; and more.

daily-intelOct 21, 20268 min
446

Dev Breakfast · 2026-10-20

Today's headline: Should You Merge AI Code You Don't Understand: Settle the Abstraction Layer Yourself First. Plus 4 more: tmux as a Remote Control: Multi-Session Claude Code and send-keys; headroom Goes Open Source: 95% Token Savings on JSON, Only 20% for Coding Agents; and more.

daily-intelOct 20, 20265 min
415

Published by Magic Tools