Skip to content

JSON Formatter

Beautify, minify, sort, and validate JSON entirely in the browser.

Loading tool…

How to use JSON Formatter

  1. 1. Paste or drop JSON. Paste a JSON document, open a file, load a public URL, or follow a share link. Nothing is uploaded.
  2. 2. Validate or repair. Syntax errors show line and column numbers. Click Repair for trailing commas, comments, or single quotes.
  3. 3. Pretty-print or minify. Choose 2-space, 4-space, or tab indentation, optionally sort keys, then copy or download.
  4. 4. Explore structure. Switch to Tree view for nested objects, or convert to YAML, XML, CSV, or TypeScript via the links below.

About this tool

JSON (JavaScript Object Notation) is the default interchange format for APIs, config files, and browser storage. It is defined by RFC 8259 and by the ECMA-404 grammar. A formatter does not change meaning: it only changes whitespace so humans can read the document and machines can still parse it. PureDevKit’s formatter runs `JSON.parse` and `JSON.stringify` in your browser, which means secrets in a payload never cross the network.

What valid JSON actually allows

JSON is stricter than a JavaScript object literal. Keys must be double-quoted strings. Trailing commas are illegal. `undefined`, functions, comments, and single quotes are illegal. Numbers cannot have leading zeros (other than `0`) and cannot be `NaN` or `Infinity`. Strings are Unicode with a small set of escapes (`\n`, `\t`, `\"`, `\\`, and `\uXXXX`). Duplicate keys are syntactically allowed but the later value wins in `JSON.parse`, which is a common source of production bugs. If a document fails to parse here, it will also fail in `fetch().json()`, `json.loads` in Python, and `encoding/json` in Go.

Pretty-print vs minify

Pretty-printing inserts indentation and newlines so diffs and code review are readable. Minifying removes insignificant whitespace to reduce bytes on the wire. For most APIs the semantic content is identical; gzip often shrinks pretty JSON close to minified size, so pretty JSON is usually the right default in logs and fixtures. Minify when you are embedding JSON in a QR payload, a URL hash, or a size-limited cookie. Sorting keys is useful before committing fixtures: unordered objects produce noisy diffs even when values did not change. Sorting is not part of the JSON spec — it is a convenience for humans and for content-addressed hashing.

When validation is not enough

A document can be valid JSON and still be the wrong shape for your service. Schema tools such as JSON Schema, Zod, TypeBox, or OpenAPI check types, required fields, and ranges. Use this formatter to get to a clean document first, then convert it with the JSON to TypeScript tool or validate it against a schema in your test suite. Be careful with `JSON.parse` on huge documents: it must load the entire tree into memory. For multi-hundred-megabyte dumps, a streaming parser is more appropriate than a browser tab.

Privacy notes for payloads

Developers often paste access tokens, session cookies, and PII into online formatters. Hosted tools that run on a server can log that data even if they claim not to. PureDevKit never sends the document anywhere: formatting happens with the platform JSON engine already in your browser. Prefer local tools whenever the payload could identify a person or authorize an API.

Common JSON errors

Trailing commas after the last property or array element break strict JSON.parse. Single-quoted strings and unquoted keys work in JavaScript literals but not in JSON. Comments (// or /* */) are illegal in JSON though common in JSONC configs — use Repair to strip them. Duplicate keys parse but the last value wins, which can hide bugs. Windows vs Unix newlines rarely break parsing but can confuse line numbers when you paste from certain editors.

Tree view and converters

After validation, Tree view helps you navigate deep API responses without horizontal scrolling. When you need another format, use the converter links for YAML, XML, CSV, or inferred TypeScript types — each has its own SEO landing page on PureDevKit so you can bookmark the direction you use most.

Code examples

JavaScript

const payload = JSON.parse(raw);
console.log(JSON.stringify(payload, null, 2));

Python

import json
print(json.dumps(json.loads(raw), indent=2, sort_keys=True))

Go

var buf bytes.Buffer
if err := json.Indent(&buf, []byte(raw), "", "  "); err != nil {
  log.Fatal(err)
}

Frequently asked questions

Related tools

All tools