惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
量子位
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
V
Visual Studio Blog
雷峰网
雷峰网
T
Tailwind CSS Blog
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
博客园 - 叶小钗
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
Y
Y Combinator Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
JSON Formatting 101: How to Debug JSON Data Like a Pro
kingfujing · 2026-06-20 · via DEV Community
Cover image for JSON Formatting 101: How to Debug JSON Data Like a Pro

kingfujing

Originally published on DevToolsHub — a collection of free, privacy-first online developer tools.


JSON (JavaScript Object Notation) is the lingua franca of modern web APIs. Whether you are debugging a REST endpoint, configuring a cloud service, or building a frontend app, you encounter JSON every day. Yet reading raw, minified JSON is a painful experience — one missing comma can break an entire payload. Here is everything you need to know about JSON formatting, validation, and debugging.

What Is JSON Formatting?

JSON formatting (also called "pretty-printing") transforms compressed, hard-to-read JSON into an indented, human-readable structure. A JSON formatter takes something like this:


json
{"name":"DevToolsHub","tools":[{"name":"JSON Formatter","url":"/json-formatter"},{"name":"Base64","url":"/base64"}],"active":true}
And turns it into this:
json

{
  "name": "DevToolsHub",
  "tools": [
    {
      "name": "JSON Formatter",
      "url": "/json-formatter"
    },
    {
      "name": "Base64",
      "url": "/base64"
    }
  ],
  "active": true
}
Why Formatting Matters
Find errors faster — malformed JSON is immediately obvious when you can see the structure
Compare responses — formatted JSON makes side-by-side comparison of API outputs easy
Share readable snippets — formatted JSON is easier to paste into documentation, issues, or PRs
Debug configurations — many cloud and DevOps tools (Terraform, Kubernetes, AWS) output JSON
Common JSON Mistakes to Watch For
1. Trailing Commas
JavaScript allows trailing commas in objects and arrays. JSON does not. This is one of the most common sources of parse errors:
json

// Invalid JSON (trailing comma)
{
  "name": "DevToolsHub",  ✗ remove this comma
}
2. Unquoted Keys
In JavaScript, object keys can be unquoted identifiers. JSON requires all keys to be wrapped in double quotes:
json

// Invalid JSON (unquoted key)
{ name: "DevToolsHub" }

// Valid JSON
{ "name": "DevToolsHub" }
3. Single Quotes Instead of Double Quotes
JSON only allows double quotes ("). Single quotes (') are not valid, even though many programming languages accept them for string literals.
4. Undefined or NaN Values
JSON supports null, true, and false, but not undefined or NaN. These values cause JSON.stringify() to silently drop keys or convert them to null.
javascript

JSON.stringify({ a: undefined, b: NaN, c: Infinity });
// → "{"b":null,"c":null}"   ← 'a' disappeared entirely!
JSON Formatting Best Practices
Use 2-Space Indentation
The standard for JSON formatting is 2-space indentation. It provides enough visual structure without wasting horizontal space. Some tools default to 4 spaces — configure them to use 2 for consistency with most API documentation.
Validate Before You Use
Always validate JSON before feeding it to your application. A good JSON formatter with validation catches errors immediately and shows you exactly where the problem is. This saves hours of debugging.
Compress for Production
When sending JSON over the wire, use the compression mode to strip all whitespace. JSON.stringify(value) (without spacing arguments) produces compressed output. A typical API response shrinks by 30-50% when compressed — saving bandwidth and improving load times.
Watch Out for Deeply Nested Structures
JSON parsers typically have a nesting depth limit (often around 100-200 levels). If you are working with highly nested data — like OpenAPI specs or complex configuration files — be aware that extremely deep structures can cause parse errors in some environments.
Real-World Debugging Scenario
Imagine you are debugging a payment API that returns this error response:
plaintext

HTTP 400
{"status":"error","code":"INVALID_PAYLOAD","message":"Validation failed","details":[{"field":"amount","error":"must be a positive number"},{"field":"currency","error":"must be one of: USD, EUR, GBP"}]}
Instead of squinting at that mess, paste it into a formatter:
json

{
  "status": "error",
  "code": "INVALID_PAYLOAD",
  "message": "Validation failed",
  "details": [
    {
      "field": "amount",
      "error": "must be a positive number"
    },
    {
      "field": "currency",
      "error": "must be one of: USD, EUR, GBP"
    }
  ]
}
Immediately you can see: two fields failed validation (amount and currency). The fix is obvious. This is the kind of insight that formatted JSON gives you in seconds versus minutes.
Putting It All Together
Whether you are a seasoned backend engineer or a frontend developer learning the ropes, mastering JSON formatting is a foundational skill. The next time you copy a curl response, paste it into a JSON formatter before trying to read it. Your eyes — and your debugging efficiency — will thank you.
If you found this guide useful, check out DevToolsHub for more free online developer tools. All tools run locally in your browser — your data never leaves your device.