About JSON Formatter with Error Line Numbers — Beautify & Validate

JSON formatter online — When a REST API returns a 47KB minified JSON blob and your console throws `SyntaxError: Unexpected token`, finding the problem by eye is nearly impossible — a missing comma at position 8,342 or a trailing comma before a closing bracket that only appears in production responses. The JSON Formatter parses your input, reports the exact line and column of any syntax violation, and produces properly indented output. It catches the mistakes that cause silent failures: single-quoted strings (valid JavaScript, invalid JSON), trailing commas (accepted by most parsers but forbidden by RFC 8259), unquoted keys, and comments (not part of the JSON spec despite appearing in many `.jsonc` files). The tree view lets you navigate deeply nested structures without scrolling through walls of indented text.

How to Use This Tool

Follow these simple steps to get accurate results in seconds. The whole process takes less than a minute for most inputs.

  1. 1

    Paste Your JSON

    Copy raw JSON from any source — browser Network tab response, log file, config file — and paste it into the input area. The parser runs automatically.

  2. 2

    Set Indentation Preference

    Select 2-space, 4-space, or tab indentation from the options. 2-space is the most common convention for JSON; 4-space matches many Python projects.

  3. 3

    Click Format or Minify

    Format expands the JSON with your chosen indentation. Minify strips all whitespace into a single line. The output replaces the previous result.

  4. 4

    Read Error Reports

    If validation fails, the error message shows the line number, column, and a description of the violation (e.g., `Line 23, Column 5: Unexpected token ,`). Fix the issue in the input area and re-format.

  5. 5

    Navigate the Tree View

    Click the arrow icons next to object and array nodes to expand or collapse them. Use this to inspect a specific nested path without scrolling the full formatted output.

  6. 6

    Copy or Download

    Click the copy button to place the result on your clipboard, or download it as a `.json` file to save directly to disk.

How It Works

The technical details of how this tool processes your input and produces accurate results.

Parse and Diagnose

The formatter passes your input through `JSON.parse()`, which tokenizes the string and constructs an in-memory object graph. When parsing fails, the native engine returns a `SyntaxError` with a character offset — the tool converts that offset to a 1-indexed line and column number. Common violations caught at this stage include unquoted object keys, single-quoted string values, trailing commas, and `undefined` literals, all of which are legal JavaScript but invalid per RFC 8259.

Recursive Serialization with Configurable Indentation

The deserialized object tree is traversed recursively by a serializer that applies your chosen indentation width (2-space, 4-space, or tab). Each object key-value pair is placed on its own line, arrays expand one element per line, and nesting depth determines indentation level. String values are re-quoted with double quotes; numeric, boolean, and null primitives serialize according to the JSON specification. The serializer preserves insertion order of object keys.

Minification and Tree View Rendering

In minify mode, the serializer strips all non-essential whitespace — spaces, newlines, and indentation — producing the smallest valid representation of the data. For tree view, the parsed object graph is walked to generate a collapsible DOM structure where each object and array node can be expanded or collapsed independently, allowing targeted inspection of deeply nested paths without scrolling through the full formatted output.

Key Features

Built to handle real workflows quickly and accurately. Each feature solves a specific problem you'd otherwise need multiple tools or manual steps to address.

Syntax Validation with Exact Error Positions

Detects missing commas, unclosed brackets, trailing commas, single-quoted strings, unquoted keys, and comments — reporting the line number and character position of each violation.

Configurable Indentation

Choose 2-space, 4-space, or tab indentation to match your project's style. The setting persists across formatting operations in the current session.

Minify and Beautify Toggle

Switch between expanded output for debugging and minified output for production — a single click strips or adds all whitespace.

Collapsible Tree View

Navigate deeply nested JSON by expanding and collapsing individual object and array nodes, rather than scrolling through hundreds of indented lines.

Double-Escaped String Handling

Properly unescapes and re-formats double-escaped strings common in API payloads (e.g., `\"lat\"` → `"lat"`), making embedded JSON readable.

Benefits of Using JSON Formatter with Error Line Numbers — Beautify & Validate

Why this tool matters and how it improves your daily work.

Pinpoints Exact Error Positions in Large Payloads

A 40KB minified API response with a missing comma produces a cryptic `Unexpected token` error. This formatter tells you line 127, column 34 — compared to `jq .` which simply refuses to parse and gives no position, or Python's `json.tool` which only shows character offset.

Catches JSON Spec Violations That JavaScript Accepts

Trailing commas, single-quoted strings, and unquoted keys parse fine in JavaScript but violate RFC 8259. The formatter flags these specifically — unlike `JSON.parse()` in loose mode or `json5` parsers that silently accept them, masking bugs that will fail in strict parsers downstream.

Tree View Beats Scrolling for Deeply Nested Data

Navigating a 15-level nested API response in a text editor means scrolling through hundreds of lines to reach one inner object. The tree view collapses everything and lets you expand only the path you care about — the same navigation pattern as browser DevTools but without the overhead of opening the Network panel.

One-Click Minify Without CLI Setup

Running `jq -c .` or `python -m json.tool --compact` requires a terminal and the right tool installed. This formatter minifies with one click, which matters when you're mid-debug in a browser and just need the compact version pasted into a config file or chat.

Common Use Cases

Real scenarios where this tool saves time and produces better results than manual methods.

Debug Webhook Payloads from Third-Party APIs

A Stripe webhook delivers a 47KB minified JSON payload and your handler crashes. Paste the raw body, spot the missing closing bracket on line 342, fix it, and re-validate — all before the retry window expires.

Validate Configuration Files Before Deployment

A stray trailing comma in `tsconfig.json` or `.eslintrc` will crash your build pipeline. The formatter catches trailing commas, unquoted keys, and single-quoted values that VS Code's auto-format may not flag if the file extension is `.json` but the content uses relaxed syntax.

Format JSON for API Documentation

Beautify raw API responses into readable examples for Swagger docs, README files, or team wikis. Consistent 2-space indentation makes the structure scannable without horizontal scrolling in documentation viewers.

Minify Production API Responses

Pretty-printed JSON with whitespace can increase payload size by 30-50%. Minify responses before deploying to staging to measure actual bandwidth impact, then verify the minified output parses correctly before pushing to production.

Who Uses This Tool

Backend Engineers Debugging Webhook Payloads

pasting raw third-party API responses to locate the exact position of syntax errors when webhook handlers crash on malformed JSON from external services

DevOps Engineers Validating Infrastructure Config

checking CI/CD pipeline JSON templates and infrastructure-as-code config files for trailing commas and unquoted keys that would cause deployment failures

Technical Writers Documenting APIs

beautifying raw API response bodies into consistently indented examples for documentation that readers can scan without horizontal scrolling

Pro Tips

Practical advice to get the most out of this tool, based on how experienced users actually work with it.

1

When an API returns a truncated response (common with timeouts on large payloads), the JSON will fail at the point of truncation. The formatter shows you exactly where the data cuts off, which tells you how much of the response you actually received and whether a retry is needed.

2

After formatting, scan for keys at inconsistent nesting depths. A key indented one level deeper than its siblings usually indicates a missing closing bracket above it that caused subsequent data to nest inside the wrong parent object.

3

Use the tree view to inspect only the specific path you're debugging rather than scrolling the full formatted output. Collapse the root node and expand only the branch you need — this is significantly faster for 20+ level nested API responses like AWS CloudWatch event payloads.

Frequently Asked Questions

Quick answers to the most common questions about this tool. If your question isn't here, contact our support team.

Why does my JSON fail validation when it works in JavaScript?
JavaScript accepts syntax that violates RFC 8259: trailing commas (`{"a": 1,}`), single-quoted strings (`{'a': 'b'}`), unquoted keys (`{a: 1}`), and comments (`// remark`). These are all invalid JSON. If you need these features, your file is JSON5, not JSON, and requires a JSON5-aware parser. The formatter deliberately rejects them to catch bugs that would fail in strict parsers like `JSON.parse()`, Python's `json.loads()`, or Go's `encoding/json`.
What does the error 'Unexpected token' mean at a position that looks correct?
The reported position is where the parser encountered something unexpected, which is often after the actual mistake. A missing comma between two key-value pairs on line 10 will report `Unexpected token` at the key on line 11 — because the parser expected a comma, not a new key. Check the line before the reported position for missing commas, brackets, or quotes.
Can the formatter handle double-escaped strings from API payloads?
Yes. Strings like `"{\"name\":\"Ada\"}"` — where JSON is serialized as a string value within another JSON object — are unescaped and formatted during beautification. The formatter recognizes the escape sequences and produces readable output for embedded JSON.
What is the difference between beautify and minify?
Beautify adds consistent indentation and line breaks so each key-value pair appears on its own line at the correct nesting depth — intended for human reading during debugging and code review. Minify strips all whitespace (spaces, newlines, tabs) to produce the shortest valid representation — intended for production deployment where smaller payloads reduce bandwidth.
Does the formatter preserve the order of object keys?
Yes. The formatter preserves the insertion order of keys as they appear in your input. The JSON specification does not require key ordering, but maintaining the original order makes diffs cleaner and keeps logically grouped keys together.
Is this JSON formatter free to use?
Yes. This JSON formatter and validator is completely free and runs in your browser. No signup required, and no usage limits. Format, validate, and minify as much JSON as you need.
How do I find the exact line of a JSON error?
Paste your JSON into the input area. If there is a syntax error, the formatter reports the exact line number, column, and description of the violation (e.g., Line 23, Column 5: Unexpected token). Fix the issue and re-validate.

Share this tool

Spread the word on social media

https://toolmetry.pro/dev/json-formatter