깨진 JSON 자동 수정 방법 — 디버깅 중지, 수정 시작

작성자

카테고리:

← 피드로
DEV Community · Faisal Yousuf · 2026-07-31 개발(SW)
Cover image for How to Auto-Fix Broken JSON — Stop Debugging, Start Fixing

Faisal Yousuf

Every developer has seen it — the dreaded SyntaxError: Unexpected token when parsing JSON. A missing comma, a trailing comma, unquoted keys, or single quotes instead of double quotes. You know the fix is simple, but finding it in a 500-line JSON response is painful.

The Problem with JSON Validators

Tools like JSONLint tell you what’s wrong — “Error at line 47, position 12.” Great. Now you get to manually hunt through nested brackets to find that one missing comma.

What if a tool could just… fix it for you?

Auto-Fix JSON — The Approach

I built a tool that automatically detects and repairs common JSON syntax errors: JSON Auto-Fix

Here’s what it repairs:

1. Missing Commas

// Broken:
{
  "name": "Alice"
  "age": 30
}

// Fixed automatically:
{
  "name": "Alice",
  "age": 30
}

Enter fullscreen mode Exit fullscreen mode

2. Unquoted Keys

// Broken:
{name: "Alice", age: 30}

// Fixed:
{"name": "Alice", "age": 30}

Enter fullscreen mode Exit fullscreen mode

3. Single Quotes

// Broken:
{'name': 'Alice', 'city': 'NYC'}

// Fixed:
{"name": "Alice", "city": "NYC"}

Enter fullscreen mode Exit fullscreen mode

4. Trailing Commas

// Broken:
{"name": "Alice", "age": 30,}

// Fixed:
{"name": "Alice", "age": 30}

Enter fullscreen mode Exit fullscreen mode

5. Unmatched Brackets

// Broken:
{"users": [{"name": "Alice"}, {"name": "Bob"}

// Fixed:
{"users": [{"name": "Alice"}, {"name": "Bob"}]}

Enter fullscreen mode Exit fullscreen mode

6. Smart/Curly Quotes

When you copy JSON from Word, Slack, or a PDF, you get typographic quotes (“like these”) instead of straight quotes. The tool replaces them automatically.

How It Works Under the Hood

The fix algorithm runs through multiple passes:

  1. BOM removal — strips invisible byte-order marks
  2. Smart quote replacement — curly → straight
  3. Single quote conversion — respecting strings already in double quotes
  4. Unquoted key detection — regex to find bare keys before colons
  5. Trailing comma removal — removes commas before } or ]
  6. Missing comma insertion — detects values on separate lines without separators
  7. Bracket balancing — counts opens vs closes and appends missing ones
  8. Final parse test — attempts JSON.parse() on the result

If it succeeds, you get perfectly formatted JSON. If it’s too broken to fix, it tells you which fixes were applied and where it still fails.

Try It

jsonsuit.com/fix-json — paste broken JSON, click Fix, done.

No sign-up. No data sent to any server (everything runs client-side in your browser).

Other JSON Tools

While I was at it, I built a full suite of JSON tools — all free, all browser-based:

Full toolkit: jsonsuit.com

What JSON tools do you use daily? Anything you wish existed? Let me know in the comments!

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다