How to Format JSON: A Simple Guide with Examples
Formatting JSON means adding consistent indentation, spaces, and line breaks so it is easier for people to read. Proper formatting does not change the actual JSON data.
By Archana Bhandari ·
Before and after formatting
Both examples contain the same valid JSON data. The formatted version is simply easier to read and debug. Already have JSON to clean up? Paste it into JSONPlease JSON Formatter to format it directly in your browser.
Before (valid minified JSON):
{"name":"Rahul","age":28,"city":"Dehradun","skills":["PHP","JavaScript"]}
After (valid formatted JSON):
{
"name": "Rahul",
"age": 28,
"city": "Dehradun",
"skills": [
"PHP",
"JavaScript"
]
}What does formatting JSON mean?
Formatting changes how JSON is displayed. It adds line breaks, indentation, and consistent spacing. It should not change keys, values, arrays, objects, data types, or the meaning of the data. Whitespace outside JSON strings generally does not change the parsed data; whitespace inside a string is part of that value and must not be changed.
- Line breaks put related parts on clear lines.
- Indentation shows which objects and arrays are nested.
- Consistent spacing makes a document easier to scan.
How to format JSON online
Open JSONPlease JSON Formatter, paste JSON or use Open JSON to choose a .json file, then select Format. Review the result and use Copy or Download if needed. Formatting and file handling happen locally in your browser.
JSON formatting example
This valid product JSON is the same before and after formatting. Indentation makes the colors array and each product property easy to find.
Unformatted valid JSON:
{"id":101,"product":"Wireless Mouse","price":799,"inStock":true,"colors":["Black","White"]}
Formatted valid JSON:
{
"id": 101,
"product": "Wireless Mouse",
"price": 799,
"inStock": true,
"colors": [
"Black",
"White"
]
}Why format JSON?
Formatting makes JSON easier to read, debug, and review. It helps you find nested values, inspect API responses, edit configuration files, compare structures manually, and spot missing or unexpected data. It is for human readability, not a claim that the formatted data is more valid.
How JSON indentation works
Each nested level is indented farther than its parent. Two spaces and four spaces are both common choices; JSON does not require a specific indentation size.
{
"user": {
"name": "Rahul",
"address": {
"city": "Dehradun",
"country": "India"
}
}
}Does JSON require formatting?
No. Both the minified and formatted examples below are valid JSON, and an application can parse either one if the syntax is correct. Formatting mainly helps people.
Valid minified JSON:
{"name":"Rahul","age":28}
Valid formatted JSON:
{
"name": "Rahul",
"age": 28
}JSON formatter, beautifier, and pretty print
These terms commonly mean the same thing: making JSON readable by adding indentation and line breaks. Different tools and programming languages may use different names, but there is no useful difference to force between them.
JSON formatter vs JSON minifier
Formatting is for human readability. Minifying removes unnecessary whitespace to make the representation more compact. Neither changes the intended JSON values or structure.
Formatted valid JSON:
{
"name": "Rahul",
"age": 28
}
Minified valid JSON:
{"name":"Rahul","age":28}Can formatting fix invalid JSON?
Not necessarily. Formatting and repairing are different operations. INVALID JSON: the trailing comma below makes it invalid standard JSON, so a formatter that requires valid JSON can reject it rather than correct it. Validate the data first, repair it where appropriate, then format the corrected result.
{
"name": "Rahul",
"city": "Dehradun",
}Formatter vs validator vs repair
JSON Formatter — makes valid JSON readable — use it when JSON is difficult to read. JSON Validator — checks JSON syntax — use it when you need to know if JSON is valid. JSON Repair — attempts to correct malformed JSON — use it when the input has fixable syntax or structure problems.
How to format JSON manually
For small documents, put each property on its own line, indent nested objects and arrays, keep commas in the right places, and do not change values accidentally. A formatter is safer and quicker for larger documents.
Before:
{"name":"Rahul","address":{"city":"Dehradun","country":"India"}}
After:
{
"name": "Rahul",
"address": {
"city": "Dehradun",
"country": "India"
}
}How to format nested JSON
Indentation reveals the structure clearly: company contains an employees array, each item is an employee object, and each employee has a skills array.
{
"company": "Example Ltd",
"employees": [
{
"name": "Rahul",
"skills": ["PHP", "JavaScript"]
},
{
"name": "Amit",
"skills": ["Python", "SQL"]
}
]
}How to format a JSON API response
API responses often arrive on one line, which is difficult to inspect while debugging. Formatting makes the user object and roles array visible without changing the response data.
Before:
{"status":"success","user":{"id":101,"name":"Rahul","roles":["editor","author"]}}
After:
{
"status": "success",
"user": {
"id": 101,
"name": "Rahul",
"roles": ["editor", "author"]
}
}How to format a JSON file
For a file such as config.json or data.json, open its content in a text editor or use the formatter's Open JSON option. Format the content, then review and save or download the result. Keep a copy of important files before making manual changes.
Common JSON formatting mistakes
Manual formatting can accidentally delete commas, add trailing commas, change quotes, break strings across lines, mix indentation styles, or alter values. Formatting does not repair invalid JSON by itself, so validate when you are unsure.
Does formatting JSON change the data?
Proper formatting preserves the underlying values and structure. The before and after examples on this page demonstrate that only layout changes. Manual editing is different: changing a character inside a string or changing a number alters the data.
- Use formatted JSON when reading, debugging, reviewing, editing, or learning.
- Use minified JSON when a compact representation is useful and human readability is not required.
Quick JSON formatting checklist
Run through this before sharing or saving edited JSON.
- Is the JSON valid?
- Are nested objects and arrays clearly indented?
- Are keys and string values still correctly quoted?
- Have any values changed accidentally?
- Are commas and brackets still correct?
- Do you need readable JSON or minified JSON?
Frequently asked questions
What does format JSON mean? It means changing the layout with indentation and line breaks to make it readable.
How do I format or beautify JSON? Paste valid JSON into a formatter or add indentation manually for small files.
What is JSON pretty print? Another common name for formatted JSON output.
Does formatting JSON change the data? Proper formatting should not change values or structure.
Can a JSON formatter fix invalid JSON? Not necessarily; validate or repair invalid input first.
How many spaces should JSON indentation use? Two or four spaces are common, but JSON does not require either.
Is minified JSON valid JSON? Yes, if its syntax is otherwise valid.
What is the difference between a formatter and validator? A formatter changes layout; a validator checks syntax.
How do I format a JSON API response? Copy the response into a formatter and inspect the readable result.