Skip to main content

developer-tools

How to Validate, Minify, and Pretty-Print JSON Online

robinhood-projects8 min read

JSON Viewer, Formatter & Editor

View, edit, and format JSON in a live interactive tree. Inline value editing, key rename, add/remove nodes, JSONC comment support, and one-click export β€” all in your browser.

Use Tool β†’

JSON to CSV Converter

Convert a JSON array of objects to CSV format instantly in your browser.

Use Tool β†’

CSV to JSON Converter

Convert CSV data to a JSON array of objects instantly in your browser.

Use Tool β†’

How to Validate, Minify, and Pretty-Print JSON Online

JSON is everywhere. Config files, API responses, environment diffs, database exports β€” you spend more time reading, writing, and debugging JSON than most developers want to admit. And yet the default experience is usually a wall of text that your eyes bounce off of, or a minified blob with a syntax error buried somewhere inside it.

This guide covers three operations every developer does with JSON on a daily basis: validating it (is this even legal JSON?), pretty-printing it (make it readable), and minifying it (strip the whitespace before it hits production). You can do all three in your browser using JSON Formatter β†’ β€” no install, no account, no copy-pasting into a terminal.


Why JSON Formatting Actually Matters

Formatting is not cosmetic. There are two distinct jobs JSON does in a software system, and they pull in opposite directions:

Human-readable JSON β€” for config files, code review, debugging, and documentation β€” needs indentation, line breaks, and visual structure. A deeply nested object written on one line is effectively unreadable.

Production JSON β€” for API payloads, build artifacts, and anything crossing a network β€” should have all that whitespace stripped. Whitespace is bytes, and bytes add up. A minified JSON payload can be 20–40% smaller than its pretty-printed equivalent, which matters at scale.

The problem is that most developers manually toggle between these two forms. They paste into an online formatter, copy back out, forget to minify before deploy, or ship a config with a trailing comma that breaks parsing in staging but not locally. A single tool that handles all three β€” validate, format, minify β€” cuts that friction down to nothing.


Pretty-Printing JSON: What It Is and How to Do It

Pretty-printing means taking compact or collapsed JSON and expanding it with consistent indentation and line breaks so humans can read it.

Take this:

{"user":{"id":42,"name":"Ada Lovelace","roles":["admin","editor"],"preferences":{"theme":"dark","notifications":true}}}

Pretty-printed with 2-space indentation, it becomes:

{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "roles": [
      "admin",
      "editor"
    ],
    "preferences": {
      "theme": "dark",
      "notifications": true
    }
  }
}

Same data. Completely different readability. The second form is what you want when you're reviewing a pull request, debugging an API response, or writing a config file by hand.

The standard is 2-space indentation (the JSON spec itself is silent on this, but 2 spaces is the near-universal convention in JavaScript ecosystems). Some teams use 4 spaces or tabs β€” the important thing is consistency.

To pretty-print in the browser: paste your JSON into JSON Formatter β†’ and click Format. The tool handles the indentation and gives you back clean, readable output instantly.

To pretty-print programmatically:

// JavaScript / Node.js
const raw = '{"name":"Ada","roles":["admin","editor"]}';
const pretty = JSON.stringify(JSON.parse(raw), null, 2);
console.log(pretty);

The third argument to JSON.stringify is the indentation level. Pass 2 for 2-space indent, 4 for 4-space, or "\t" for tabs.


Minifying JSON for Production

Minification strips all non-essential whitespace β€” spaces, tabs, newlines β€” without changing the data. The result is a single line of dense JSON that parsers love and humans hate.

Take the pretty-printed example above. Minified:

{"user":{"id":42,"name":"Ada Lovelace","roles":["admin","editor"],"preferences":{"theme":"dark","notifications":true}}}

That is the exact same JSON. Every key, every value, every nested object β€” all intact. The only difference is the whitespace is gone.

When does this matter?

  • API responses β€” smaller payloads mean faster network transfer and lower bandwidth costs
  • Build artifacts β€” JSON config files bundled with a frontend app should be minified like any other asset
  • Environment configs β€” some systems have hard limits on environment variable size; minified JSON fits more cleanly
  • Diffing between environments β€” two config files with different indentation styles will produce noisy diffs; normalizing both to minified first makes the actual changes obvious

To minify in the browser: paste into JSON Formatter β†’ and click Minify. You get a single-line output ready to copy.

To minify programmatically:

// JavaScript / Node.js
const pretty = `{
  "name": "Ada",
  "roles": ["admin", "editor"]
}`;
 
const minified = JSON.stringify(JSON.parse(pretty));
console.log(minified);
// {"name":"Ada","roles":["admin","editor"]}

JSON.stringify with no spacing argument produces minified output by default.


Validating JSON Syntax

Validation answers one question: is this valid JSON? Not whether the data makes sense for your application β€” just whether the syntax is legal according to the JSON spec.

This sounds trivial until you're staring at a parse error from a config file and can't figure out which of the 400 lines is broken.

Common causes of invalid JSON:

Trailing commas

{
  "name": "Ada",
  "roles": ["admin", "editor"],
}

That trailing comma after "editor" is illegal in JSON (it's fine in JavaScript and in JSONC, but not in strict JSON). Parsers will reject this.

Single quotes instead of double quotes

{
  'name': 'Ada'
}

JSON requires double quotes for all strings and all keys. Single quotes are not valid.

Unquoted keys

{
  name: "Ada"
}

Again, keys must be strings in JSON. This is valid JavaScript object literal syntax but not valid JSON.

Comments

{
  // author config
  "name": "Ada"
}

JSON does not support comments. If you need comments in a config file, look at JSONC, YAML, or TOML instead β€” the YAML vs JSON vs TOML comparison covers the tradeoffs in depth.

Missing or mismatched brackets

{
  "user": {
    "name": "Ada"
  
}

An unclosed object or array will fail parsing. In a large file this is easy to miss by eye.

When you paste invalid JSON into JSON Formatter β†’, it highlights the error inline β€” showing you the exact line and character where the problem is. You fix it directly in the editor and validate again. No terminal, no JSON.parse in a REPL, no guessing.


Common JSON Errors and How to Fix Them

ErrorCauseFix
Unexpected token ,Trailing commaRemove the comma after the last item
Unexpected token 'Single-quoted stringReplace with double quotes
Unexpected token }Missing closing bracket elsewhereCheck that all { have a matching }
Unexpected end of JSON inputTruncated inputEnsure the full JSON was pasted
Unexpected token /Comment in JSONRemove comments; use JSONC if you need them
SyntaxError: Unexpected token uundefined valueJSON does not support undefined; use null

One debugging pattern worth knowing: if you have a large, deeply nested JSON blob and can't find the error, paste it into the validator first. It will point to the exact position. Then you can fix it there and pretty-print the corrected version.


A Practical JSON Workflow (Step by Step)

Here is the sequence that covers most real-world JSON tasks in one shot:

  1. Copy the JSON from wherever it lives β€” an API response, a config file, a database export, a terminal output.

  2. Paste it into JSON Formatter β†’.

  3. Validate first. If there are syntax errors, the tool highlights them inline. Fix them before doing anything else.

  4. Pretty-print if you need to read the data, review a structure, or share it with a teammate. Click Format.

  5. Minify if the output is going somewhere that doesn't need whitespace β€” an API payload, a build artifact, an env variable. Click Minify.

  6. Copy the result and paste it where it needs to go.

That's the whole workflow. No install, no terminal, no half-broken browser extension. For more advanced work β€” like editing values inline, navigating a tree view, or converting JSON to CSV β€” the JSON Viewer and Editor guide covers the next level of tooling.


When to Use Each Operation

SituationOperation
Received an API response you can't readPretty-print
Writing a config file by handPretty-print while editing, validate before saving
Preparing a JSON payload for a POST requestMinify
Comparing two config files from different environmentsMinify both, then diff
Debugging a parse errorValidate
Code review of a JSON schemaPretty-print
Bundling JSON into a frontend buildMinify

Try It Now

Paste any JSON into JSON Formatter β†’ β€” valid or broken, minified or bloated β€” and it handles the rest. Validate, format, and minify in your browser with no sign-up and no file uploads.

If you work with JSON regularly, also worth bookmarking: the JSON Viewer and Editor for inline tree editing, and the YAML vs JSON vs TOML guide if you're deciding which format to use for a config file in the first place.