Skip to content
YAS.SH
Developer🔒 Browser (client-side)API available📴 Works offlinebeginner

JSON Formatter

Beautifies (pretty-prints) or minifies JSON so it is easy to read or compact to store.

Data stays in your browser
Ready to runInstant execution
All tools →
Result

What does this tool do?

Beautifies (pretty-prints) or minifies JSON so it is easy to read or compact to store.

Why would I use it?

  • You copied JSON from an API response or config file and it is one unreadable line.
  • You want to shrink a JSON payload before storing or transmitting it.
  • You need consistent indentation before committing a config file.

Real-life example

Input
{"name":"yas","links":["/tools","/docs"]}
Output
{
  "name": "yas",
  "links": [
    "/tools",
    "/docs"
  ]
}

The formatter adds indentation and line breaks without changing the data.

Input → Process → Output → Next

Input
Paste any JSON text (object, array, or scalar).
Process
The browser parses the JSON and re-serializes it with 2-space indentation.
Output
Pretty-printed JSON — or an exact error with line/column when the JSON is invalid.
Next action
Fix any reported syntax error, then use the JSON Validator to confirm it parses.

Common mistakes

  • Formatting JSON that is actually invalid — you get an error, not output.
  • Expecting formatter to fix trailing commas (they are invalid JSON).
  • Pasting huge JSON into the browser — keep it under 64 KB for the API.

What the result means

Valid JSON is reformatted; invalid JSON produces a precise error message so you can fix the exact location.

Privacy & security

Your input is processed entirely in your browser and never sent to a YAS server.

API

Endpoint
POST https://yas.sh/api/v1/tools/json-formatter
Request Header
Content-Type: application/json
cURL
curl -X POST "https://yas.sh/api/v1/tools/json-formatter" \
  -H "Content-Type: application/json" \
  -d '{"input":"{\"a\":1,\"b\":[2,3]}","mode":"minify"}'
JavaScript
const res = await fetch("https://yas.sh/api/v1/tools/json-formatter", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "input": "{\"a\":1,\"b\":[2,3]}",
  "mode": "minify"
}),
});
const data = await res.json();
Python
import requests

r = requests.post("https://yas.sh/api/v1/tools/json-formatter", json={"input":"{\"a\":1,\"b\":[2,3]}","mode":"minify"})
data = r.json()
FieldTypeRequiredDescription
inputstringYesJSON text
mode"beautify" | "minify"No (default "beautify")Direction
Success response
{ "slug": "json-formatter", "result": "{\"a\":1,\"b\":[2,3]}", "mode": "minify" }

Beautify (2-space indent) or minify JSON.

Error responses
  • 400 VALIDATION_ERROR — invalid input or unsupported option.
  • 413 PAYLOAD_TOO_LARGE — input exceeds the 64 KB limit.
  • 429 RATE_LIMIT_EXCEEDED — rate limit exceeded (60 req/min).
Limits
  • Maximum input: 64 KB per request.
  • Rate limit: 60 requests/min per IP address.
  • Authenticated accounts benefit from higher tier quotas.

JSON Formatter: technical reference, use cases and FAQ

How JSON Formatter works

Formatting is a parse-then-serialize round trip, not a text transformation. The input string is parsed by the JavaScript engine's JSON parser into an in-memory value (object, array, string, number, boolean or null), then re-serialized with JSON.stringify(value, null, 2) for pretty output or JSON.stringify(value) for minified output. Because the intermediate representation is a real value and not a token stream, anything the parser rejects is reported as a syntax error rather than silently reformatted.

The round trip is lossless for data but not for text. Key order is preserved (V8 keeps insertion order for string keys, and integer-like keys are ordered numerically per the ECMAScript specification), whitespace and any original indentation are discarded, and escape sequences are normalised — \u0041 becomes A, and characters that must be escaped in JSON (quote, backslash, control characters below U+0020) are re-escaped in their shortest legal form.

Numbers are the one place where a round trip can change the literal text. JSON has no number type of its own; the parser produces an IEEE-754 double. A 20-digit integer such as 12345678901234567890 comes back as 12345678901234567000, and 1.0 is re-serialized as 1. If your payload carries large IDs, transport them as strings — this is why Twitter/X, Stripe and Discord all expose object IDs as JSON strings.

  1. Step 1
    Raw JSON text
  2. Step 2
    JSON.parse → in-memory value
  3. Step 3
    JSON.stringify with indent
  4. Step 4
    Formatted output or precise syntax error
Parse-then-serialize round trip

When to use it: real-world scenarios

Reading an API response captured from the network tab

Production responses are minified to a single line. Pasting the body here restores structure so you can see which object the missing field actually belongs to. Pair it with the JSON Validator when the response is truncated by a proxy — a truncated body fails to parse at the exact character where the stream was cut.

Normalising config files before committing

Two developers with different editors produce diffs full of whitespace noise. Running every .json config through the formatter with the same 2-space indentation makes pull-request diffs show only real changes. This is the same normalisation prettier applies, without adding a dependency to the repository.

Shrinking a payload before storing it

Minified mode removes every byte of insignificant whitespace, which typically cuts 15–30% from a pretty-printed document. That matters when you are writing to a column with a size limit, a cookie, a query parameter, or a message-queue payload with a per-message cap.

Auditing JSON pasted from a log line

Structured logs embed JSON inside an escaped string field. Decode the escaping first, then format — the formatter will reject the still-escaped text, which is itself the signal that you are looking at a doubly-encoded value rather than an object.

Pro tips

  • If the formatter reports an error at position 0 or 1, check for a UTF-8 byte-order mark (EF BB BF) or a leading blank line. JSON.parse treats a BOM as an unexpected token; strip it before parsing.
  • JSON with comments (.jsonc, tsconfig.json) and trailing commas is not JSON. Use the JSON Repair tool for those inputs — the formatter is deliberately strict so it can be trusted as a validator.
  • NDJSON / JSON Lines files must be formatted one line at a time. A file of concatenated objects is not a single JSON document and will fail at the second opening brace.
  • Formatting does not sort keys. If you need a stable, diff-friendly ordering across services, sort keys in your build step; a formatter that reordered keys would change the meaning of documents where order is semantically used (for example, some OpenAPI tooling).

Limitations and edge cases

What this tool deliberately does not do, and where it will disagree with other implementations.

  • Browser formatting is bounded by memory and main-thread time. Documents beyond a few megabytes will freeze the tab during parse; the API path caps input at 64 KB by design.
  • Duplicate keys are not reported. RFC 8259 leaves duplicate names undefined behaviour, and JSON.parse keeps the last occurrence, so {"a":1,"a":2} silently formats to {"a": 2}.
  • Number precision beyond 2^53-1 is lost, as is the distinction between 1, 1.0 and 1e0. There is no configuration that avoids this without a custom big-number parser.
  • The tool formats; it does not validate against a schema. Structural correctness (required fields, types) needs JSON Schema validation, which is a different operation.

Frequently asked questions

Is my JSON uploaded to a server?
No. Formatting runs entirely in your browser using the built-in JSON parser, so the document never leaves the tab. The identical operation is also exposed at POST /api/v1/tools/json-formatter for automation, and that path does receive the payload — use the page, not the API, for sensitive data.
Why does my JSON fail with 'Unexpected token' when it looks correct?
The three usual causes are single quotes instead of double quotes, a trailing comma after the last element, and smart quotes introduced by a word processor. JSON permits only double quotes (U+0022); a curly quote (U+201C) is an ordinary character and cannot open a string.
What indentation does the formatter use, and can I change it?
Two spaces, matching the default of prettier, npm and the Node.js ecosystem. Tabs and four-space output are not offered because mixed indentation across a repository is the problem the formatter exists to remove.
Does minifying JSON change its meaning?
No. Whitespace between tokens is insignificant in JSON, so a minified document parses to exactly the same value. The only differences a round trip can introduce are number formatting and normalised escape sequences.
Ask YAS AI
🍪 Cookies & privacy. Essential cookies keep you signed in and remember language and theme. Google AdSense and reCAPTCHA are Google technologies: AdSense runs only after Accept All; reCAPTCHA loads on sign-in and contact forms. See how Google uses data: https://policies.google.com/technologies/partner-sites cookie policy · privacy policy.
Settings