Text & Developer tool

JSON Formatter and Validator: Fix and Beautify JSON

Beautify, minify, validate, view and compare JSON in one place.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type

Valid JSON

{
  "name": "Ravi",
  "skills": [
    "Java",
    "SQL"
  ],
  "fresher": true
}
How it works

This JSON formatter adds line breaks and spaces so JSON is easy to read. It can also minify JSON, show the line and column of an error, display a tree, and compare two JSON texts.

This JSON formatter makes messy JSON easy to read and tells you where it is broken. JSON is a text format that programs use to share data, often through a web API.

How to use the JSON formatter online

  1. Paste your JSON.
  2. Choose format, minify or validate.
  3. If there is an error, go to the line and column shown.
  4. Use the tree view to open and close parts of the data.
  5. To compare, paste a second JSON text.

JSON formatter: beautify example

This is hard to read:

{"name":"Asha","skills":["Java","SQL"],"active":true}

After you beautify it:

{
  "name": "Asha",
  "skills": ["Java", "SQL"],
  "active": true
}

The tool may put each list item on its own line. The data is still the same, because spaces between JSON items have no meaning.

Minify does the reverse. It removes extra spaces and lines, which makes a file smaller to send.

JSON formatter and validator: common errors

Wrong Right Reason
{'a': 1} {"a": 1} Use double quotes
{a: 1} {"a": 1} Keys need quotes
[1, 2,] [1, 2] No comma after the last item
{"a": True} {"a": true} true, false and null are lowercase
{"a": 01} {"a": 1} No leading zeros

An error message may point just after the real problem. If line 5 looks fine, check the end of line 4 for a missing comma or quote.

Common mistake: A common mistake beginners make is copying a JavaScript object and expecting it to be valid JSON. JavaScript allows single quotes, unquoted keys and comments. JSON does not.

JSON formatter viewer: reading the tree

The tree view shows objects and lists as branches. Close the parts you do not need and open one branch at a time. This helps you find the path to a value.

For the data below, the path to "Hyderabad" is user.address.city:

{
  "user": {
    "address": { "city": "Hyderabad" }
  }
}

List positions start at 0. The first skill in a list is skills[0].

JSON formatter: compare online

Paste two JSON texts to see what changed. This helps when an API worked yesterday and fails today.

Two rules help you read the result:

  • Key order does not matter. {"a":1,"b":2} and {"b":2,"a":1} hold the same data.
  • List order does matter. [1,2] and [2,1] are different.

Also compare types. The number 5 and the text "5" look alike but can break a program.

Pro tip: Format both texts first. Differences are much easier to see when the layout matches.

Keep private data out

Do not paste passwords, API keys, tokens or customer data into any online tool. Replace them with sample values such as "xxxx" first. If a secret must be created, use the password generator and store it safely.

Where JSON is used

JSON carries data between a page and a server. Start with what is a REST API, then see it in the Node.js tutorial. Document databases store similar shapes, as the MongoDB tutorial shows. Front-end developers meet JSON lists often, so JavaScript array methods are worth learning next.

In code, JavaScript has two built-in functions: JSON.parse reads JSON text, and JSON.stringify writes it. JSON.stringify(data, null, 2) formats it with two spaces.

Frequently asked questions

What does a JSON formatter do?
It adds line breaks and indentation without changing the data, so nested objects and lists are easy to read.
Why is my JSON invalid?
Common causes are a comma after the last item, single quotes, missing quotes around a key, or a comment. Use the line and column shown to find the spot.
Does formatting change my data?
It is meant to change only layout. Watch very large numbers, because JavaScript-based tools can lose digits beyond about 16.
What is the difference between minify and beautify?
Beautify adds spaces and lines for people. Minify removes them to make the text smaller for sending.
Can JSON have comments?
No. Standard JSON does not allow comments. Remove them or use a format that supports them.

Try another tool

See all free tools
Chat with us