Volver al blog
JSONMay 6, 2026por Dogufy Team

How to Format JSON (Pretty-Print) and Validate It — Plus Common Fixes

Need to pretty-print JSON, minify it, or fix “invalid JSON” errors? This guide shows the quickest copy/paste workflow, common parsing problems (trailing commas, smart quotes, single quotes), and how to compare two JSON versions safely.

How to Format JSON (Pretty-Print) and Validate It — Plus Common Fixes

How to Format JSON (Pretty-Print) and Validate It — Plus Common Fixes

When JSON is hard to read (or refuses to parse), everything slows down: debugging, API testing, config reviews, even copy/paste between tools.

This article gives you a fast, reliable workflow using Dogufy’s JSON Formatter, plus the most common reasons JSON becomes “invalid” and how to fix them.

Quick answer (featured snippet)

To format and validate JSON:

  1. Open JSON Formatter.
  2. Paste your JSON into the input box.
  3. Click Format (pretty-print) to make it readable, or Minify to compress it.
  4. If you see an error, fix common issues (like trailing commas, single quotes, or smart quotes) and format again.
  5. Copy the output and use it in your app, API request, or config file.

What “formatting JSON” actually does (and what it doesn’t)

Pretty-print (format)

Formatting re-writes JSON with:

  • consistent indentation (commonly 2 spaces),
  • clean line breaks,
  • stable ordering of what’s already there.

It doesn’t change the data—just how it looks.

Minify

Minifying removes whitespace so your JSON becomes one compact line (useful for logs, URLs, or reducing payload size in copy/paste contexts).

Validate

Validation answers a single question: is this valid JSON syntax?
If the formatter shows an error, your input is not valid JSON yet.

Step-by-step: Format (pretty-print) JSON online

  1. Open JSON Formatter.
  2. Paste your JSON into Input JSON.
  3. Choose an indent size (2, 4, or 8 spaces).
  4. Click Format.
  5. Click Copy to copy the formatted output.

Tip: If you’re cleaning up JSON for documentation, keep indent at 2 spaces—it’s the most common convention and tends to be easiest to scan.

Step-by-step: Minify JSON (make it smaller for transport)

Use minified JSON when you:

  • want to paste JSON into a single-line form field,
  • store JSON in an env var (where line breaks cause headaches),
  • need a compact snippet for logs or quick sharing.

Steps:

  1. Open JSON Formatter.
  2. Paste your JSON.
  3. Click Minify.
  4. Copy the output.

Common “Invalid JSON” errors (and quick fixes)

Below are the most common copy/paste problems. Fix the input, then run Format again.

1) Trailing commas

JSON does not allow trailing commas in objects or arrays.

Invalid:

{
  "name": "Dogufy",
}

Fix:

{
  "name": "Dogufy"
}

2) Single quotes instead of double quotes

JSON requires double quotes around strings and keys.

Invalid:

{'a': 1, 'b': 2}

Fix:

{"a": 1, "b": 2}

3) “Smart quotes” from Word/Docs/Slack

If you see curly quotes like “ ” or ‘ ’, replace them with straight quotes (").

4) Comments in JSON

Many tools accept “JSON with comments” (sometimes called JSONC), but strict JSON does not.

Invalid:

{
  // this is a comment
  "enabled": true
}

Fix: remove comments (or use a JSONC-aware environment).

5) Unquoted keys

Invalid:

{a: 1}

Fix:

{"a": 1}

Make JSON reviews easier: compare two versions with a diff

If you’re reviewing a config change or an API response update, formatting both versions first makes diffs dramatically cleaner.

Workflow:

  1. Format Version A in JSON Formatter and copy the output.
  2. Format Version B in JSON Formatter and copy the output.
  3. Paste them into Diff Checker to highlight what changed.

This avoids false positives caused by different whitespace or indentation.

Practical tips (so your JSON stays readable)

  • Use consistent indentation (2 spaces is a solid default).
  • Keep arrays and objects multi-line once they get “wide”.
  • Sort keys only if your team’s style guide requires it (formatting alone won’t re-order keys intentionally).
  • For secrets, never paste credentials into tools you don’t trust—redact keys/tokens before formatting.

FAQ

Is pretty-printed JSON “different” from the original JSON?

No—the data is the same. Pretty-printing changes whitespace (indentation and line breaks) to make the structure easier to read.

Why does JSON parse in JavaScript but fail in a JSON formatter?

Some JavaScript environments accept non-JSON syntax (like comments, trailing commas, or single quotes). A strict formatter validates real JSON, so it will reject those extras.

What indentation should I use: 2 or 4 spaces?

Use 2 spaces for most APIs and docs, and 4 spaces if your project’s style guide prefers it. The key is consistency.

How can I find the exact change between two JSON blobs?

Format both first with JSON Formatter, then compare them using Diff Checker.

Consentimiento de cookies

Solo activamos la analítica después de tu consentimiento. El almacenamiento necesario permanece activo para la seguridad y el funcionamiento básico del sitio.

Política de privacidad

How to Format JSON (Pretty-Print) and Validate It — Plus Common Fixes - dogufy.com | Dogufy