ToolPilot
developer tools 5 min readβ€’ Updated 2026-09-04

How to Format, Validate, and Debug Broken JSON

A quick troubleshooting guide for common JSON syntax errors, escaping rules, and client-side formatting tips.

The 3 Most Common JSON Errors

1. Trailing Commas: In JavaScript, { "a": 1, } is valid. In standard JSON, a comma after the final key-value pair throws a fatal syntax error.

2. Single Quotes: Keys and string values in JSON MUST be enclosed in double quotes ("key": "value"), never single quotes.

3. Unescaped Characters: Backslashes, quotes, and newlines must be properly escaped with backslashes.

How to Read a Parser Error Message

When a validator reports something like "Unexpected token } in JSON at position 148", the position number is your fastest route to the bug. Most formatters will highlight or scroll to that character, and the problem is almost always immediately before it β€” a missing comma between two properties, or a stray comma before a closing brace or bracket.

A reliable debugging habit is to format (pretty-print) the JSON first. Collapsed, single-line JSON hides structural mistakes; expanding it onto indented lines makes an unbalanced bracket or a misplaced comma jump out visually. Because ToolPilot formats entirely in your browser, you can paste even sensitive payloads to inspect them without the data leaving your machine.

JSON vs. JavaScript Object Literals

Developers coming from JavaScript often trip over the fact that JSON is stricter than the object syntax they write in code. JSON does not allow comments, does not allow trailing commas, does not allow single-quoted strings, and requires every key to be a double-quoted string. Functions, undefined, and dates are also not valid JSON values.

This strictness is intentional: JSON is a data-interchange format meant to be parsed identically by every language, so it deliberately removes the conveniences that only make sense inside JavaScript source code. When you copy an object out of your editor and it fails to validate, these differences are the usual culprit.

Interactive Tools for This Guide

Put this guide into practice

Frequently Asked Questions

Why does my JSON fail with a trailing comma?

The JSON standard does not permit a comma after the last item in an object or array. Remove the final comma before the closing brace or bracket and it will validate.

Is it safe to paste sensitive JSON into ToolPilot?

Yes. The JSON formatter and validator run entirely in your browser. Your payload is never uploaded to a server, so you can inspect tokens or private data safely.