JSON Formatter vs JSON Validator: What's the Difference (and When You Need Both)

Mirsal Saidu Updated 7 min read

A JSON formatter pretty-prints code; a JSON validator catches errors. Here's the 60-second workflow that combines both, plus free browser-only tools.

JSON Formatter vs JSON Validator: What's the Difference (and When You Need Both)

What is the difference between a JSON formatter and a JSON validator?

A JSON formatter indents and line-breaks raw JSON for readability. A JSON validator parses the same JSON and reports syntax errors (missing commas, unquoted keys, trailing commas, mismatched braces). Many online tools, including our free formatter, do both in one pass: they parse the input (validating), then re-serialize it with indentation (formatting). If the parse fails, you get the parser's error message instead of output.

The two words get mixed up because one button often does both jobs. The difference matters when the JSON is valid but still wrong for your app: a formatter will happily indent it, and a plain syntax validator will pass it. Catching that second kind of problem takes a JSON Schema. If you are new to the syntax itself, what is JSON explains objects, arrays and the six value types first.

How to format and validate JSON in 60 seconds

  1. Open our free JSON Formatter. It parses and formats in your browser, so the JSON you paste isn't uploaded.
  2. Paste your JSON into the Input JSON box. The tool takes pasted text; to check a .json file, open it in an editor and copy the contents.
  3. Click Validate or Format / Prettify. Valid input shows a green "Valid JSON" status (Validate also names the root type, such as object or array) and Format fills the output panel. Invalid input shows ✕ Invalid JSON: followed by your browser's parser message, which often includes the line and column of the problem.
  4. Fix and re-run. Common errors: a trailing comma after the last array element, single quotes instead of double, unquoted property names. Common JSON formatting errors lists the exact message each one produces.
  5. Convert if needed. Use the CSV to JSON converter to turn tabular data into a JSON array.

Formatter vs validator: side by side

OperationWhat it doesOutputWhen you need it
FormatAdds whitespace, indentation, line breaksReadable JSONCode review, debugging, documentation
ValidateParses against the JSON spec (RFC 8259)Pass/fail + error locationBefore sending to an API, before commit, in CI
MinifyStrips all whitespaceCompact JSONNetwork payloads, embedded config
DiffCompares two JSON payloadsStructural deltaAPI response regression, contract tests

What a JSON validator checks, and the three levels of validation

"Valid" can mean three different things, and each one needs a different tool.

  1. Syntax. Does the text follow the JSON grammar in RFC 8259? Quotes, commas, brackets and literals are checked, and nothing else. This is what our formatter's Validate button does, using your browser's built-in JSON.parse.
  2. Structure. Does the data have the fields and types your app expects? A syntax check can't know that "id" should be a number. A JSON Schema validator can.
  3. Meaning. Is an end date after its start date, or is a price positive? These rules live in your own code, because neither the JSON grammar nor a typical schema knows your business.

Our tool covers level 1. On success, Validate prints ✓ Valid JSON with the root type (object, array, string, number or boolean); on failure it prints the parser's first error and stops there.

Validate JSON against a JSON Schema

A JSON Schema is itself a JSON document that describes what valid data looks like: which keys are required and what type each value must have. Here is a small schema, a record that passes a syntax check, and what the Python jsonschema library (version 4.19, Draft 2020-12 rules) reports for it:

Schema:
{
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "id": {"type": "integer"},
    "email": {"type": "string"},
    "tags": {"type": "array", "items": {"type": "string"}}
  }
}

Data (valid JSON syntax):
{"id": "1042", "tags": ["admin"]}

jsonschema 4.19 output:
'email' is a required property
'1042' is not of type 'integer'

Both problems are invisible to a formatter. The id is a string because it has quotes, and the missing email is simply absent. Change the data to {"id": 1042, "email": "jane@example.com", "tags": ["admin"]} and the same validator returns no errors. JSON Schema is a different thing from schema.org structured data, the JSON-LD that search engines read; our schema markup generator writes the second kind.

The 7 most common JSON errors a validator catches

  • Trailing comma: {"a": 1, "b": 2,} is invalid JSON, though JSON5 and JavaScript object literals allow it.
  • Single quotes: {'a': 1} needs double quotes.
  • Unquoted keys: {a: 1} fails because keys must be strings in double quotes.
  • Unescaped backslash: "path": "C:\Users" needs \\ (a double backslash).
  • Comments: JSON has no comment syntax, so strip // and /* */.
  • NaN or Infinity: not valid JSON values. Use null or a number.
  • Mismatched braces: easy to cause when editing by hand. Count opening and closing characters, or use the error position to see where the parser gave up.

Can a JSON validator fix the errors for you?

Our formatter doesn't change invalid input. It shows the first error and leaves the text as you pasted it, so you decide what the fix is. Some online tools sold as a "JSON validator and fixer" go further and repair the text by guessing: they swap single quotes for double ones, drop trailing commas and close open brackets.

The quote and comma repairs are usually safe. Bracket repair is where guessing hurts. Take a response that was cut off mid-transfer:

{"items": [1, 2

A fixer that closes the brackets turns it into {"items":[1,2]}, which validates, and nothing tells you the rest of the list is gone. A strict parser rejects the original (jq 1.7 says Unfinished JSON term at EOF), and that rejection is what you want when the data came from an API. Use repair tools on hand-written config if you like, then compare the before and after so you can see every change they made.

Format and validate JSON from the command line

In a terminal, jq does the same job:

echo '{"a":1,"b":[2,3]}' | jq .
# pretty-prints. Exit code 0 = valid, non-zero = syntax error

For Python: python -m json.tool input.json. For Node: node -e "console.log(JSON.parse(require('fs').readFileSync('in.json')))".

Which JSON validator to use where

Where you areOptionWhat it checks
Browser, one-off pasteOur JSON formatter and validatorSyntax, plus the root type
Code editorVS Code checks .json files as you type; Notepad++ needs a pluginSyntax, and a schema if the file names one in "$schema" (VS Code)
Terminal or CIjq . or python -m json.toolSyntax; jq exits with code 5 on a parse error
Application codeA JSON Schema library such as Python's jsonschemaStructure and types

For a quick check of something you copied from a log or a Network tab, the browser tool is fastest. For anything that runs on every commit, put the check in a script so nobody has to remember it. If the JSON you are checking is the payload of a login token, our JWT decoder splits the token and shows the header and payload as JSON, and how to decode a JWT safely explains what to look for.

How to validate JSON online without uploading it

Pasting JSON into a website is fine when the page does the work itself. To check that a tool really runs in the browser, open DevTools (F12), switch to the Network tab, clear it, then paste and click Validate. A page that parses locally makes no new request when you click. Our formatter passes, because it calls JSON.parse in the page, and you can format with Ctrl+Enter (Cmd+Enter on a Mac) once the input is valid. How to format JSON in your browser walks through the formatter's indent options and tree view in more detail.

Frequently asked questions

Can a JSON formatter break my data?

For ordinary data, no: only whitespace changes. A formatter that parses and re-serializes (ours uses JSON.parse and JSON.stringify) does rewrite some edge cases the way JavaScript reads them, though. Integers above 9,007,199,254,740,991 lose precision (9007199254740993 comes back as 9007199254740992), duplicate keys collapse to the last value, 1.0 becomes 1, 1e2 becomes 100, and integer-like keys such as "10" move to the front of the object. If that matters, compare the before and after in the Diff Checker.

Should I validate JSON on the server or client?

Both. Client-side validation catches typos before the request, and server-side validation catches malicious or malformed payloads. Never rely on client validation alone.

What's the difference between JSON and JSON5?

JSON5 is a superset of JSON that allows comments, trailing commas, single quotes and unquoted keys. Standard parsers such as JSON.parse reject that syntax, so keep JSON5 to config files your own tooling reads.

Is a JSON validator the same as a JSON linter?

People use the words loosely. A validator answers yes or no against the grammar or a schema. A linter usually adds style rules on top, such as consistent indentation or sorted keys, which valid JSON doesn't require.

Why does my JSON pass one validator and fail another?

Some tools accept extensions. Python's json module reads NaN, and JSON5-aware tools accept comments and trailing commas, while a browser's JSON.parse rejects all three. Validate with the strictest parser your data will meet, which for web apps is usually the browser.

Related free tools


Share this article:
Mirsal Saidu

Mirsal Saidu

Digital & Performance Marketer