← Developer

JSON Formatter

Pretty-print, minify, validate, and sort JSON, with the exact line and column of any error.

Input

Paste any JSON. The output updates as you type.
Checking…

Output

Size
–
Depth
–
Keys
–
Lines out
–

      
      
Objects–
Arrays–
Strings–
Numbers–
Booleans / nulls–
Minified size–

About this tool

This JSON formatter pretty-prints, minifies, validates, and sorts JSON documents entirely in your browser. Paste an API response, a config file, or a log line and it re-indents it with 2 spaces, 4 spaces, or tabs; strips whitespace for a compact payload; sorts object keys alphabetically at every level; or escapes the whole document as a JSON string literal for embedding. When the input is invalid it reports the line and column of the first bad token with a caret excerpt so you can jump straight to the problem. It is meant for developers debugging APIs, writers editing JSON config, and anyone who needs to check that a document is well-formed before shipping it.

How it works

Validation uses the browser's native JSON.parse, which follows ECMA-404 / RFC 8259. Because JavaScript engines report parse errors differently, the exact error position comes from a small tolerant scanner in the page: it walks the text with the JSON grammar (objects, arrays, strings with escape validation, numbers, literals) and stops at the first character that cannot continue a valid document, then converts that offset to a line and column. Formatting is JSON.stringify(value, null, indent); minifying is JSON.stringify(value) with no indent. Sort keys rebuilds every object with its keys in code-point order, recursing into arrays and nested objects. Depth and key counts come from a recursive walk of the parsed value; size is the UTF-8 byte length of the text.

Frequently asked questions

Why does the error position differ from my editor?

Editors and engines disagree about where an error 'is'. This page points at the first character that cannot legally continue the document under the RFC 8259 grammar, using 1-based line and column numbers. A trailing comma, for example, is reported at the closing bracket that follows it, because the comma itself was legal until the bracket arrived.

Does sorting keys change the meaning of my JSON?

No. RFC 8259 says object member order is not significant, and JSON.parse in every major engine gives the same result regardless of key order. Sorting only helps humans compare two documents or produce stable diffs. Array order is preserved because it is meaningful.

What does 'Escape as string' do?

It turns the whole input into a single JSON string literal: quotes become \", backslashes double up, newlines become \n, and the result is wrapped in quotes. That is what you need when a JSON document has to be stored inside another JSON field, an environment variable, or a string in source code. 'Unescape' reverses it.

Are large numbers or duplicate keys preserved?

JSON.parse converts numbers to IEEE 754 doubles, so integers above 9,007,199,254,740,991 (2^53 - 1) lose precision, and 1.0 becomes 1. When an object has duplicate keys, the last value wins and the earlier ones are dropped. If you need exact big integers, keep them as strings in the source document.

Related tools

Base64 Encode / Decode · URL Encode / Decode · Regex Tester · Hash Generator · UUID Generator · JWT Decoder · HTML Entity Encoder · Color Converter · Password Generator · Number Base Converter · QR Code Generator · Chmod Calculator

Browse all Developer Tools, or go back to every free tool on HeroYears.