Reconnecting… Connection lost. Reload Session expired. Reload

JSON Formatter

Format and validate JSON with configurable indentation, optional key sorting, and instant error feedback.

By Pankaj Kumar · DevToolsHub· Last updated Jun 2026
Input Section

JSON input

Output Section

Formatted output

JSON result

What is a JSON formatter?

A JSON formatter — also called a JSON beautifier or pretty-printer — takes compact or minified JSON text and reformats it with consistent indentation and line breaks, making the structure immediately human-readable. It also acts as a validator: if your JSON contains a syntax error (a missing quote, a trailing comma, mismatched brackets), the formatter catches it and reports exactly where the problem is so you can fix it without guessing.

JSON (JavaScript Object Notation) is specified in RFC 8259 and is the dominant data-interchange format for web APIs, configuration files, and database exports. Almost every developer works with it daily, yet raw API responses and minified production payloads are often a single unbroken line — impossible to read or debug without formatting.

How to use this tool

  1. Paste your raw, minified, or partially formatted JSON into the input editor on the left.
  2. Click the Format button (or press Ctrl+Enter).
  3. Choose indent size (2 or 4 spaces) and enable Sort keys to alphabetise every object's keys recursively.
  4. Use the Copy button to copy the result to your clipboard.

The formatter tolerates trailing commas and inline // comments (common in JSON5 and JSONC configuration files), stripping them silently before reformatting.

Input/output specification

PropertyDetail
StandardRFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format
Input toleranceAccepts RFC 8259 JSON plus trailing commas and // line comments (JSONC/JSON5 supersets)
Output encodingUTF-8 with BOM stripped; all non-ASCII characters preserved as-is
Max payloadEffectively unlimited for browser RAM; typical API responses format in < 1 ms
Processing100 % client-side — System.Text.Json.JsonDocument in WebAssembly; no network request

Understanding JSON value types (RFC 8259 §3)

  • Object — unordered set of key-value pairs in { }. Keys must be double-quoted strings; duplicate keys are technically undefined behaviour.
  • Array — ordered list of values in [ ], separated by commas.
  • String — Unicode characters in double quotes. Escape sequences: \" \\ \/ \b \f \n \r \t \uXXXX.
  • Number — integer or floating-point (no quotes, no hex/octal literals). Arbitrary precision numbers should use string form.
  • Booleantrue or false (lowercase only).
  • Nullnull (lowercase only).

Common JSON validation errors

ErrorCauseFix
Unexpected tokenSingle quotes used instead of double quotesReplace all ' with "
Trailing commaComma after the last item in an object or arrayRemove the final comma before } or ]
Unexpected end of inputMissing closing bracket or braceEnsure every { has a } and every [ has a ]
Invalid escape sequenceBackslash not followed by a valid escape characterDouble the backslash: \\ for a literal backslash
Duplicate keySame key appears twice in an objectRemove or rename the duplicate key

Minified vs formatted JSON

Minified JSON strips all whitespace to reduce payload size. Formatted JSON restores indentation and line breaks. Minification reduces a typical formatted object by 15–30%; for debugging and development, formatted output is always preferable.

Common use cases

  • Debugging API responses — paste the raw curl response, format it, inspect the field you need
  • Config file reviewpackage.json, tsconfig.json, appsettings.json are easier to diff when consistently formatted
  • Webhook inspection — log the raw body, paste here, understand the event structure immediately
  • Schema comparison — enable Sort keys to normalise two JSON objects before diffing
  • NoSQL export cleanup — format single-line documents before reviewing
Native code equivalents
Production-ready snippets — same logic the tool runs, in your language
All processing is client-side · zero data retention
JavaScript
Python
Go
cURL / jq
// Format JSON with configurable indent
function formatJson(raw, indent = 2, sortKeys = false) {
  const parsed = JSON.parse(raw);
  if (sortKeys) return JSON.stringify(sortDeep(parsed), null, indent);
  return JSON.stringify(parsed, null, indent);
}

function sortDeep(value) {
  if (Array.isArray(value)) return value.map(sortDeep);
  if (value !== null && typeof value === 'object') {
    return Object.fromEntries(
      Object.keys(value).sort().map(k => [k, sortDeep(value[k])])
    );
  }
  return value;
}

const pretty = formatJson('{"b":2,"a":1}', 2, true);
console.log(pretty);
// {
//   "a": 1,
//   "b": 2
// }
FAQ
Does the formatter validate JSON?

Yes. Invalid JSON returns an error message with the line and column number rather than formatted output.

Is any data stored?

No. Formatting runs entirely within your browser session using System.Text.Json in memory. Your JSON is never sent to any external server or logged.

What does Sort keys do?

It reorders all object keys alphabetically at every nesting level. Useful for normalising two JSON objects before comparing them with a diff tool.

What is the difference between minified and formatted JSON?

Minified JSON strips all whitespace to reduce file size. Formatted JSON adds indentation and line breaks to make it human-readable.

Can I format JSON5 or JSONC?

Yes. Trailing commas and // line comments are stripped silently before formatting, so you can paste JSONC config files directly.

What RFC governs JSON?

RFC 8259 (superseding RFC 7159 and RFC 4627) defines the JSON format. This tool targets strict RFC 8259 compliance in its output.