usefmtly

JSON Formatter & Validator

Free JSON formatter and validator. Paste any JSON to format it with 2-space, 4-space, or tab indentation. Validates JSON syntax and shows errors inline. Sort keys alphabetically. 100% client-side.

Valid
0Input chars
0Keys
Indent
Input
Output

How to use the JSON Formatter

  1. Paste your JSON into the input panel on the left, or click “Try sample” to load an example.
  2. See validation instantly — if your JSON has syntax errors, a red border appears on the input and the error message is shown below it. Valid JSON shows a green “✓ Valid” indicator in the stats bar.
  3. Choose your indent style — switch between 2 spaces, 4 spaces, or tabs using the segmented control in the toolbar. Toggle “Sort Keys” to alphabetically sort all object keys.
  4. Copy the formatted output — click the Copy button in the output panel header to copy the beautified JSON to your clipboard. Use “Minify” to collapse the JSON back to a single line.

JSON syntax rules

JSON (JavaScript Object Notation) has strict syntax rules. Here is a quick reference:

  • ·Keys must be strings wrapped in double quotes — e.g. "name" not name.
  • ·String values must use double quotes — single quotes are not valid JSON.
  • ·Trailing commas are not allowed — the last item in an object or array must not have a comma.
  • ·Numbers are unquoted — e.g. 42 or 3.14.
  • ·Booleans are lowercase: true or false.
  • ·Null is lowercase: null.
  • ·Comments are not supported in standard JSON.
  • ·The root value can be an object, array, string, number, boolean, or null.

Need to format YAML too? Try the YAML Formatter.

Common JSON errors and how to fix them

The error messages from JSON.parse() can be cryptic. Here are the most common ones and their causes:

ErrorCauseFix
Unexpected tokenTrailing comma after the last item in an object or arrayRemove the trailing comma
Unexpected token 'Single quotes used for strings or keysReplace single quotes with double quotes
Unexpected end of JSON inputMissing closing bracket, brace, or quoteCheck that all {, [, and " are closed
Unexpected token //JavaScript-style comments in JSONRemove all comments — JSON does not support them
Unexpected token uUnquoted value like undefinedUse null instead of undefined
Expected property name or }Key not wrapped in double quotesWrap all keys in double quotes: "key": value
Unexpected numberNumber used as a key, or extra comma before a numberEnsure keys are strings; check for duplicate commas

Frequently Asked Questions

What is a JSON formatter?

A JSON formatter takes minified or poorly indented JSON and reformats it with consistent spacing and indentation, making it readable. It also validates that the JSON is syntactically correct.

What does validation do?

The formatter parses the JSON using JavaScript's built-in JSON.parse(). If the JSON has syntax errors (missing quotes, trailing commas, etc.), the error message is shown below the input.

What is the difference between 2-space and 4-space indent?

Indentation is a style preference. 2 spaces is common in JavaScript/Node.js projects; 4 spaces is common in Python and some other languages. Tab indentation is preferred in some style guides.

What does Sort Keys do?

Sort Keys alphabetically reorders all object keys at every level of nesting. This is useful for normalizing JSON for diffing, version control, or readability.

Is my JSON sent to a server?

No — all formatting and validation happens in your browser using JavaScript. Your JSON never leaves your device.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data interchange format. It is human-readable, widely supported, and used in APIs, config files, and databases.

Related Tools