# JSON Formatter

> Format, validate and minify JSON as you type, with 2-space, 4-space or tab indentation. See the exact line and column of any error, with a plain-English reason.

- Open the tool: https://overtooled.com/json-formatter
- Category: Developer
- Privacy: Runs entirely in your browser. Nothing is uploaded, no account is needed, and it works offline once loaded.
- Price: free, no sign-up
- Keywords: json, format, validate, beautify, minify, pretty

## In short

Format, validate, and minify JSON with clear error messages.

## Overview

Checks and formats JSON live as you type: pretty-print with 2 spaces, 4 spaces or tabs, or minify. Useful for reading a compact API response, shrinking a config file, or finding exactly why a JSON document will not parse. Validity comes from the browser's JSON.parse; the output is re-indented from the original tokens, so values are never re-serialized.

## Features

- Live: the input is analysed 150 ms after typing pauses (400 ms for large inputs); no Format/Validate buttons
- Inputs of 100,000 characters or more are parsed and formatted in a Web Worker (src/workers/jsonFormat.worker.js); a newer input cancels an older run
- Valid JSON / Invalid JSON / Checking... badge next to the input label
- Errors located by the tool's own scanner, identical in every browser (Safari reports no position): "Line L, column C: reason" in a reserved line under the input, plus an output card with an excerpt, a caret, and "Show in input" (focuses and selects the spot)
- Plain-English reasons: trailing comma, missing comma, single/curly quotes, unquoted keys, comments, leading zeros, bad escapes, line breaks in strings, unclosed brackets (with where they opened), NaN/undefined/True/None, BOM, non-breaking spaces
- Token-preserving formatting: numbers (12345678901234567890, 1.50, -0), string escapes and duplicate keys are kept exactly as written
- Output style: 2 spaces, 4 spaces, Tabs, or Minify; the choice is remembered (localStorage)
- Output stats: line count and UTF-8 byte size of the output
- Outputs over 200,000 characters show a truncated preview; Copy, Download and Pipeline use the full text
- Copy, Download (.json / .min.json) and Pipeline buttons; they hide while a newer input is waiting, so a stale result is never copied
- Sample and Clear buttons

## How to use it

1. Paste JSON into the Input JSON box (or click Sample)
2. Read the badge; if invalid, the line, column and reason appear under the box ("Show in input" jumps there)
3. Pick 2 spaces, 4 spaces, Tabs or Minify above the output
4. Copy or download the result, or send it to another tool via Pipeline

## Inputs

- Any text pasted into the input box; it must be strict JSON (RFC 8259 / ECMA-404 as implemented by JSON.parse)
- Output style: 2 spaces (default), 4 spaces, tab, or minify

## Outputs

- Formatted or minified JSON text in a read-only code panel (plain text, no syntax coloring)
- A valid/invalid status with line, column, reason and excerpt
- Copy to clipboard, download as a .json file, or send to another tool via Pipeline

## Limits and notes

- Strict JSON only: comments, trailing commas, single quotes, unquoted keys, NaN, and Infinity are rejected (no JSON5/JSONC support)
- Only the first error is reported
- Multi-megabyte documents: parsing never blocks typing, but the browser's own text box gets slow to edit (about 70-100 ms per key for an 800 KB, 70,000-line document in Chromium)
- No sort-keys option; no file upload (paste text)
- The input itself is not saved; it is lost on reload
- Runs entirely in the browser; no data is uploaded

## Questions and answers

### How does the JSON Formatter work?

It checks and formats your JSON as you type, a moment after you stop. The browser's JSON.parse() decides whether the text is valid; the output is then re-indented from your original text with 2 spaces, 4 spaces, a tab, or no whitespace (Minify), so numbers and strings are kept exactly as you wrote them: a 20-digit number keeps every digit, 1.50 stays 1.50, and duplicate keys are not dropped. Inputs of 100,000 characters or more are processed in a background worker so typing never waits for a parse. Your indent choice is remembered.

### How do I format JSON online?

Paste your JSON into the input box. The badge next to the label says Valid JSON or Invalid JSON, and the formatted result appears in the Output panel with Copy, Download and Pipeline buttons. Pick 2 spaces, 4 spaces, Tabs or Minify above the output to change the style.

### Why is my JSON invalid?

Common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted property names, comments, a missing comma between items, or curly quotes pasted from a document. The tool finds the first error itself (so it works the same in every browser, including Safari, which reports no position), shows its line and column under the input with a plain-English reason and a snippet with a caret, and "Show in input" selects the spot.

## Related tools

- [File Anatomy Viewer](https://overtooled.com/file-anatomy.md): Upload any file to explore its binary structure with annotated hex dumps and format-specific explanations
- [File Viewer](https://overtooled.com/file-viewer.md): Drop any file to view it -- images, videos, audio, code, JSON, CSV, PDF, fonts, and binary files with magic bytes detection
- [JSON / CSV Converter](https://overtooled.com/json-csv.md): Convert JSON to CSV and CSV to JSON in either direction
- [JSON to Table Viewer](https://overtooled.com/json-to-table.md): View JSON data as a readable, sortable HTML table

---
Overtooled: 179 free tools that run in your browser. Index of all tools: https://overtooled.com/llms.txt
