JSON Formatter

Validate JSON and make it readable with indentation, or minify it to save space. Parsing happens in your browser.

How to use

  1. Paste your JSON.
  2. Choose pretty print or minify.
  3. Press Format.

Good to know

If the JSON is invalid you will see the parser error message.

This tool is free, needs no sign-up and runs in your browser. Explore more on the Tools page.

What does a JSON formatter actually do, and when do you need one?

JSON, short for JavaScript Object Notation, is the everyday language of web APIs, configuration files and data exports. Machines read it effortlessly, but humans do not. A response from an API often arrives as one enormous line with no spaces or breaks, and a single misplaced comma can make the whole thing unusable. A JSON formatter does two jobs at once: it checks that the text is valid, and it rearranges valid text so you can read it, or squeezes it down so it is as small as possible.

You reach for one when you are debugging an API response, editing a config file by hand, preparing a sample for documentation, or trying to figure out why an application refuses to load a file. This guide explains what the tool does under the hood, the syntax rules that trip people up, and how to read the error messages you will see.

How does the formatter work under the hood?

The process has two stages. First the text is parsed: a JSON parser reads it character by character and checks it against the JSON grammar. If anything is out of place, such as a missing quote or an extra comma, parsing stops and reports an error, usually including the position where it lost track. If parsing succeeds, you have a valid data structure in memory made of objects, arrays, strings, numbers, booleans and null.

Second, that structure is written back out as text. For pretty printing, the output is serialised with a two space indent, so each nested level is shifted two spaces to the right and every key or array item sits on its own line. For minifying, it is serialised with no extra whitespace at all. Because the text is regenerated from the parsed data, the formatter also normalises spacing for you. Key order is preserved, and the data itself does not change, only its layout.

Formatting versus validating: what is the difference?

These are related but distinct. Validating answers a yes or no question: does this text follow JSON syntax? Formatting changes how valid JSON looks without changing what it means. This tool does both because you cannot reliably reformat something that cannot be parsed. If your input is invalid, you get the parser error instead of formatted output.

It is worth being clear about what validation does not cover. A document can be perfectly valid JSON and still be wrong for your purpose. It might be missing a field your application expects, contain a number where a string should be, or use a misspelled key. Checking data against a specific structure is called schema validation, and this tool does not do that. It only confirms that the text is well formed.

How do you use the tool?

  1. Paste your JSON into the input area.
  2. Choose Pretty print to indent with 2 spaces, or Minify to remove all unnecessary whitespace.
  3. Press Format. If the JSON is valid, copy the result from the output. If it is invalid, read the error message, fix the problem in the input and press Format again.

When fixing errors, work from the first one reported. Parsers stop at the first problem, so later errors may be hidden until you correct the earlier one.

What are the core JSON syntax rules?

JSON is stricter than it looks, and stricter than JavaScript object syntax, which it resembles. The essentials are:

  • Data is built from objects (curly braces holding key and value pairs) and arrays (square brackets holding ordered values).
  • Keys must be strings wrapped in double quotes.
  • String values also use double quotes. Single quotes are not allowed.
  • Allowed value types are string, number, true, false, null, object and array.
  • Items are separated by commas, but there must be no comma after the last item.
  • Comments are not part of the standard.
  • Special characters inside strings, such as double quotes, backslashes and line breaks, must be escaped with a backslash.

What does valid JSON look like before and after formatting?

Here is a compact record as it might arrive from an API:

{"user":{"id":42,"name":"Priya","active":true,"roles":["editor","admin"]},"lastLogin":null}

Pretty printed with a 2 space indent, it becomes:

{
  "user": {
    "id": 42,
    "name": "Priya",
    "active": true,
    "roles": [
      "editor",
      "admin"
    ]
  },
  "lastLogin": null
}

Now the structure is obvious: a top level object with a nested user object and a lastLogin value of null. Minifying reverses the process and returns to the single line version, which is useful when you want smaller payloads or need to embed JSON in another file.

What are the most common JSON errors and how do you fix them?

Trailing commas

A comma after the final item is the most frequent mistake, especially for people used to JavaScript. This is invalid:

{
  "name": "Ravi",
  "age": 30,
}

Delete the comma after 30 and it parses.

Single quotes

Writing {'name': 'Ravi'} fails because JSON requires double quotes for both keys and strings. Replace each single quote with a double quote, taking care with apostrophes inside text.

Unquoted keys

This looks natural but is invalid:

{ name: "Ravi" }

The corrected version is:

{ "name": "Ravi" }

Comments

Lines starting with // or blocks wrapped in /* */ are not allowed. Remove them, or if you need notes, store them as a regular field such as "_note": "explanation here". Some tools accept extended formats that permit comments, but standard JSON does not.

Unescaped characters and wrong values

A raw line break or an unescaped double quote inside a string will break parsing. Write "He said \"hello\"" rather than putting bare quotes inside. Also remember that values such as True, undefined and NaN are not valid. Use lowercase true and null, and leave out values that have no JSON equivalent.

Mismatched brackets

Every opening brace or bracket needs a matching closing one. Pretty printing a nearly valid document in an editor often makes a missing bracket easy to spot by eye, because the indentation stops lining up.

How does this help when working with APIs?

When you call an API from a script, a command line tool or a browser, the response body is frequently minified to save bandwidth. Pasting it into a formatter lets you inspect the structure, find the field you need and confirm the shape of the data before writing code against it. In the other direction, when you are crafting a request body by hand, running it through the validator before sending catches syntax slips that would otherwise produce a vague "bad request" error from the server. Minifying is handy when you must put a JSON string into a single line field, an environment variable or a compact log entry.

What tips make JSON easier to work with?

  • Format first, then read. Do not try to understand a one line blob.
  • Fix the first reported error before hunting for others.
  • Keep numbers as numbers and avoid wrapping them in quotes unless they are identifiers where leading zeros matter.
  • Do not paste real secrets, passwords or tokens into any shared screenshot or document after formatting. The tool is private, but your screenshots may not be.

Who is this tool for?

Developers use it daily for debugging requests and responses. Data analysts use it to inspect exports before loading them. Technical writers format examples for documentation. Students learning web development use it to see how nested data is organised.

Is my data private?

Yes. Validation, formatting and minifying all run inside your browser. Nothing you paste is sent to a server or stored, so it is reasonable to check configuration snippets and internal data samples. As always, avoid pasting credentials onto any device you do not control.

What are the limitations?

The tool checks syntax only. It cannot tell you whether your data matches an expected schema, and it does not repair broken JSON automatically. Parser error messages come from your browser's built in JSON parser, so their wording and level of detail can vary between browsers. Very large inputs, such as many megabytes of data, may slow your browser. Also, numbers beyond the range of standard floating point precision can lose accuracy when parsed and rewritten, so be careful with very large integer identifiers.

Frequently asked questions

Why does my JSON fail when it works in JavaScript code?

JavaScript object literals allow unquoted keys, single quotes, comments and trailing commas, while strict JSON allows none of them. Convert those to the stricter form and the parser will accept it.

Does formatting change my data?

No. Pretty printing and minifying change only whitespace. The keys, values and their order stay the same.

What is the difference between pretty print and minify?

Pretty printing adds line breaks and a 2 space indent to make the structure easy to read. Minifying removes all unnecessary whitespace to produce the smallest possible text.

Can JSON contain comments?

Not in the standard. If you need to annotate data, add a descriptive field, or keep the notes in separate documentation.

Why does the error message point to a position?

The parser reports where it hit something unexpected. The real mistake is often just before that spot, such as a missing comma on the previous line.

Wrapping up

Readable, valid JSON saves time at every stage, from debugging to documentation. Paste, check the error if there is one, and copy the clean result. If you handle encoded data in the same workflow, the Base64 Encoder and Decoder pairs well with this tool, since API payloads often carry Base64 strings. You may also find the Word Counter, the Slug Generator and the Password Generator useful, and the rest of our free tools are one click away.

Scroll to Top