usefmtly

JSON Formatter & Validator

JSON Formatter — 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
Input
Output

How to use the JSON Formatter

  1. Paste your JSON into the input panel on the left, or click “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 compact or messy JSON and rewrites it with consistent indentation so nested objects and arrays are easy to scan. This tool also validates the structure while formatting, which means you can paste an API response, config file, or log payload and immediately see whether the JSON is readable and syntactically valid.

What does validation do?

Validation runs your input through JavaScript's native JSON.parse(), the same parser many frontend tools rely on. If the JSON is broken because of trailing commas, missing quotes, invalid numbers, or an unfinished bracket, the tool stops formatting and shows the parser error so you can fix the exact issue instead of guessing.

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

The data stays identical either way. Two spaces is the most common default in JavaScript projects because it keeps files compact, while four spaces can make deeply nested payloads easier to follow in documentation or code reviews. Tabs are useful when your editor or team style guide prefers adjustable indentation width.

What does Sort Keys do?

Sort Keys alphabetically reorders object keys at every nesting level before the formatted JSON is printed. That makes repeated payloads easier to diff in Git, easier to compare in pull requests, and easier to scan when two objects contain the same fields in different orders. Arrays stay in their original order.

Is my JSON sent to a server?

No. The formatter runs entirely in your browser, so the JSON you paste never gets uploaded to a backend just to be beautified. That matters when you are working with internal API responses, local config files, or redacted log snippets and want a quick readability pass without sending data to another service.

What is JSON?

JSON stands for JavaScript Object Notation. It is a plain-text format for structured data that uses objects, arrays, strings, numbers, booleans, and null values. Even though it came from JavaScript, it is now a universal format used by REST APIs, frontend apps, server configs, CLI tools, and data exports across almost every language.

Related Tools