# JSON Formatter & Validator

URL: https://hifreetools.com/developer/json-formatter

> Paste JSON to pretty-print it, validate it, or minify it. Errors are reported with a clear message so you can find the problem fast.

## Quick answer

A JSON formatter parses your JSON and re-prints it with consistent indentation so it’s easy to read, while validating that the syntax is correct. Minifying does the reverse — it removes whitespace to make the smallest valid JSON.

## Formula

- JSON text = ws value ws; value = object / array / string / number / true / false / null (RFC 8259)
- Format: one item per line, each nesting level indented by 2 spaces, 4 spaces or a tab; Minify: no whitespace between tokens
- Numbers, key order and duplicate keys are kept exactly as written; strings are re-escaped minimally
- Saved = (1 − minified bytes ÷ input bytes) × 100, sizes in UTF-8 bytes
- Errors: the first character that breaks the grammar, as line (\n-separated) and column (characters)

Your text is parsed with the browser’s built-in JSON parser. If it’s valid, it’s re-serialized with two-space indentation (formatting) or with no whitespace (minifying). If it’s invalid, the parser’s error message is shown so you can locate the issue. Everything happens locally — your JSON is never sent to a server.

## Inputs

- JSON input; default {"name":"Ada","langs":["Ada","C"],"active":true,"score":9.5,"address":{"city":"London","zip":null}}
- Indent — one of: 2 spaces, 4 spaces, Tab; default 2
- Sort keys A–Z; default false

## Worked examples (computed by the page's own function)

- JSON input = {"name":"Ada","langs":["Ada","C"]}, Indent = 2 → Output = {
  "name": "Ada",
  "langs": [
    "Ada",
    "C"
  ]
}, Valid JSON = 1, Lines = 7, Output size (bytes) = 56  (7 lines, 56 B)
- JSON input = {
  "a": 1,
  "b": [true, null]
} → Output = {"a":1,"b":[true,null]}, Valid JSON = 1, Lines = 1, Output size (bytes) = 23  (33 B → 23 B)
- JSON input = {"a":1,} → Valid JSON = 0, Error line = 1, Error column = 7, Error offset = 6  (trailing-comma at line 1, column 7)

## Verification

Checked against 25 reference cases (expected values computed independently). Reviewed 2026-10-27. Latest change 2026-10-28: Moved to the schema formatter renderer with a sourced ledger. Errors now name the problem (trailing comma, single quotes, comment, …) with its exact line and column instead of the browser's raw message; the error line is highlighted. Added 4-space/tab indent, sort keys, a validate-only mode, byte sizes and percent saved (from JSON Minifier). Numbers such as 1.0, 1e5 and integers above 2^53 are now kept exactly as written, and duplicate keys are kept and counted instead of silently dropped.

## FAQ

**What does formatting JSON do?**
It re-prints valid JSON with consistent indentation and line breaks so the structure is easy to read. The data itself is unchanged.

**How does validation work?**
The tool tries to parse your text as JSON. If parsing fails, it shows the error so you can fix the syntax; if it succeeds, your JSON is valid.

**What is minifying?**
Minifying removes all unnecessary whitespace to produce the smallest valid JSON — useful for reducing payload size.

**Is my JSON sent to a server?**
No. Parsing and formatting run entirely in your browser, so sensitive payloads and tokens never leave your device.

**Why does it reject comments?**
Standard JSON doesn’t support comments. Formats like JSON5 or JSONC do, but they aren’t valid strict JSON.

**Can it handle very large JSON files?**
The tool runs in your browser, so the practical limit depends on available memory. For files over 10 MB, a command-line tool like jq is more reliable.

**Does it support JSON5 or JSONC with comments?**
No, this tool strictly parses JSON per RFC 8259. JSON5 and JSONC allow comments and unquoted keys that standard JSON forbids.


## Sources

- [RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259)
- [ECMA-404 — The JSON data interchange syntax](https://ecma-international.org/publications-and-standards/standards/ecma-404/)
- [json.org — Introducing JSON](https://www.json.org/)
- [Python 3 documentation — json (reference used for the ledger)](https://docs.python.org/3/library/json.html)

Runs in the browser; nothing is uploaded. Cite as: HIFreeTools, "JSON Formatter & Validator", https://hifreetools.com/developer/json-formatter
