Every developer eventually runs into the same wall: an API response, a config file, or a chunk of data lands in front of you as one impossibly long line, and reading it means squinting character by character trying to find where one field ends and the next begins. Formatting that data takes a few seconds once you know the process, and this guide walks through exactly how to do it, whether you are dealing with a small API response or a genuinely large file.
None of the steps below require any special software or technical background beyond copying and pasting. The process is the same whether you are formatting a five-field object or a deeply nested response with hundreds of entries.
Step-by-Step: How to Format JSON Online
The basic process is the same regardless of where your JSON came from. Here is how to format it using ToolMatoâs
JSON Formatter:
- Copy your raw JSON: Select the data from wherever it currently lives, an API response, a terminal window, a config file, or a message someone sent you.
- Paste it into the formatter: Drop the raw text into the input box on the toolâs page.
- Choose your indentation setting: Most formatters let you pick two or four spaces for indentation, so choose whichever matches your preference or your projectâs convention.
- Run the formatter: The tool parses the structure and rebuilds it with consistent indentation and line breaks between fields.
- Review and copy the result: Check that nested objects and arrays look correct, then copy the formatted output or download it for reference.
That is the entire process for the vast majority of cases. The sections below cover a few specific scenarios that come up often enough to be worth walking through individually.
How to Format a Minified JSON API Response
API responses are almost always minified by default, since removing whitespace reduces the amount of data transferred over the network. When you need to actually read one, the process is identical to formatting any other JSON, but there are a couple of practical tips worth knowing.
If you are viewing the response inside your browserâs developer tools, most modern browsers already apply basic formatting automatically when you inspect a network request under the Network tab. For anything beyond that quick inline view, copying the raw response body and pasting it into a dedicated formatter gives you a cleaner, more readable result, especially for deeply nested responses where a browserâs built-in view can still be cramped.
Here is a typical minified API response:
{"status":"success","data":{"orders":[{"id":1001,"total":49.99},{"id":1002,"total":89.50}]},"count":2}
And the same response after formatting:
{
"status": "success",
"data": {
"orders": [
{ "id": 1001, "total": 49.99 },
{ "id": 1002, "total": 89.50 }
]
},
"count": 2
}
Notice how each order object inside the array is now clearly separated, making it immediately obvious that
data.orders contains two distinct records rather than one continuous block of values.
This kind of formatting is especially useful when an API is returning something unexpected. A field that should contain a number showing up as a string, an array that is empty when it should have entries, or a nested object missing a key you expected, all of these are far easier to notice once the response is laid out clearly instead of buried inside a single dense line.
How to Format a Large JSON File
Large JSON files, anything from a sizable configuration file to an exported dataset with thousands of records, follow the same formatting process, but a few practical adjustments help.
For genuinely large files, pasting the entire contents into a browser-based tool works fine most of the time, though extremely large files, in the tens of megabytes, may process more slowly or hit a size limit depending on the specific tool. In those cases, splitting the file into smaller sections before formatting, or using a code editorâs built-in formatting extension instead of an online tool, tends to work more reliably.
It also helps to think about what you actually need from a large file before formatting the whole thing. If you only need to inspect one section of a large dataset, extracting that portion first and formatting just that piece is often faster and easier to work with than scrolling through a fully formatted multi-thousand-line file.
How to Add Indentation to JSON Manually vs With a Tool
Technically, you can add indentation to a small JSON snippet by hand, pressing tab or space after each opening brace and matching it on the closing one. For anything beyond a handful of fields, this becomes tedious and genuinely error-prone, since it is easy to miscount nesting levels once an object contains several other objects and arrays.
A formatter removes this risk entirely by calculating indentation programmatically based on the actual structure of the data, rather than relying on a person to track nesting depth by eye. For any JSON beyond a trivial example, using a tool is faster and considerably more reliable than adding indentation manually.
There is also a subtler risk with manual indentation that is easy to overlook: consistency across a team. If one person indents by hand using two spaces and another uses four, files edited by different people end up looking inconsistent even when each individual edit was reasonable. A formatter, whether run manually or configured to run automatically, removes this variation entirely by applying the same rule every time, regardless of who triggered it.
Understanding Nested JSON Formatting
Nested JSON, objects and arrays containing other objects and arrays, is where formatting genuinely earns its value. A flat object with three fields barely needs formatting to be readable. An object with fields that are themselves objects, several layers deep, is nearly impossible to parse visually without it.
Here is an example of moderately nested JSON:
{"user":{"profile":{"name":"Sam","address":{"city":"Austin","zip":"78701"}},"preferences":{"theme":"dark","notifications":true}}}
Formatted, the nesting becomes immediately clear:
{
"user": {
"profile": {
"name": "Sam",
"address": {
"city": "Austin",
"zip": "78701"
}
},
"preferences": {
"theme": "dark",
"notifications": true
}
}
}
Each level of indentation corresponds to one level of nesting. The
city field, four levels deep, sits four indentation steps in, making the relationship between
user,
profile,
address, and
city visually obvious rather than something you have to trace manually through brace after brace.
This visual mapping becomes essential once nesting goes deeper than three or four levels, which happens routinely in real API responses from larger applications. Without formatting, tracking which closing brace belongs to which opening one requires counting characters. With formatting, the answer is right there in how far each line is indented.
Common Problems When Formatting JSON
- The formatter shows an error instead of formatted output: This usually means the JSON is not actually valid, often due to a trailing comma, a missing quotation mark, or single quotes used instead of double quotes.
- Numbers or booleans appear as quoted strings: If a formatter is preserving quotes around values that should be numbers or true and false, the original data itself likely had those values as strings, which the formatter is simply reflecting accurately.
- The output looks correct but the data still fails elsewhere: Formatting confirms readability, not correctness. If a program is still rejecting your JSON after formatting, the underlying data has a genuine syntax issue that a validator would catch.
- Arrays of simple values stay on one line while arrays of objects expand: This is typically intentional behavior, keeping simple arrays compact while expanding complex ones, rather than a sign anything went wrong.
- Special characters or emoji look broken after formatting: This usually reflects an encoding mismatch in how the data was copied or pasted, rather than an issue with the formatter itself. Re-copying the original source text directly typically resolves it.
Formatting JSON in Different Contexts
Depending on where you encounter unformatted JSON, a few different approaches make sense.
- In a code editor: Most modern editors, including VS Code, can format a JSON file automatically, either through a built-in feature or an extension like Prettier, without needing to leave the editor at all.
- In browser developer tools: Network request bodies and console output are often formatted automatically or can be expanded by clicking through the nested structure directly in the inspector.
- In the terminal: Command-line tools built specifically for JSON can pipe a response through a formatter directly, which is common in scripting and automation workflows.
- Anywhere else: An online formatter covers everything the situations above do not, a config file someone emailed you, a snippet from a support ticket, or a machine without your usual development tools set up.
Formatting JSON Before Sharing or Documenting It
Formatted JSON is not just useful for your own debugging, it matters just as much when you are handing data off to someone else. Pasting a raw, minified response into a support ticket, a Slack message, or a piece of documentation forces the next person to format it themselves before they can even start looking at it.
Taking the extra few seconds to format JSON before sharing it respects the time of whoever receives it next, whether that is a teammate, a client, or a future version of yourself reading through old documentation. This is especially worth doing in API documentation specifically, since example responses that are properly formatted are dramatically easier for other developers to understand and reference correctly.
Best Practices for Formatting JSON
- Format JSON before trying to read or debug it manually, rather than scanning a compressed response by eye.
- Keep configuration files formatted consistently in version control, since consistent formatting produces meaningful, readable diffs.
- For large files, extract just the section you need before formatting, rather than formatting the entire file unnecessarily.
- Use an editor extension for JSON files you edit frequently, and an online formatter for one-off external data.
- If formatting produces an error, treat that as a signal to check for actual syntax issues rather than assuming the formatter is broken.
- Format any JSON before pasting it into documentation, a support ticket, or a message to a teammate, rather than leaving that step for whoever reads it next.
Formatting the Rest of Your Project
JSON rarely appears without JavaScript, HTML, and CSS somewhere nearby in a real project. If formatting JSON has made your API responses easier to work with, the same principle applies across the rest of your codebase. ToolMatoâs
JavaScript Formatter,
HTML Formatter, and
CSS Formatter apply the same readability principle to everything else you are working on.
Frequently Asked Questions
How do I format JSON online for free?
Paste your raw JSON into an online JSON formatter, choose your indentation preference, and run the tool. Most online formatters are free to use without an account and process the data directly in your browser.
How do I make minified JSON readable again?
Paste the minified data into a JSON formatter and run it. The tool reconstructs the nesting structure and adds consistent indentation and line breaks, turning a single compressed line back into a readable, structured document.
Can I format a JSON API response directly in my browser?
Yes, in two ways. Browser developer tools often display network responses with basic formatting automatically, and you can also copy the raw response and paste it into a dedicated online formatter for a cleaner, fully expanded view.
How do I add indentation to JSON without a tool?
For a very short snippet, you can add indentation manually by matching each opening brace with consistent spacing on nested lines, but this becomes error-prone quickly. A formatter calculates indentation automatically and is far more reliable for anything beyond a trivial example.
What should I do if formatting JSON produces an error?
An error usually means the JSON is not actually valid, often due to a trailing comma, a missing quotation mark, or unquoted keys. Check the specific error message, since most formatters and validators point to roughly where the problem occurred.
Can I format a large JSON file with thousands of lines?
Most online formatters handle large files without issue, though extremely large files may process more slowly or hit a size limit. For very large datasets, a code editorâs formatting extension or splitting the file into smaller sections often works more reliably.
Does formatting JSON change the actual data?
No. Formatting only adjusts whitespace, indentation, and line breaks. The keys, values, and structure of the data remain exactly the same before and after formatting.
How do I pretty print JSON without installing software?
Use an online JSON formatter, which runs entirely in your browser. Paste your data in, format it, and copy the result out, all without downloading or installing anything.
Why does nested JSON look so different before and after formatting?
Unformatted JSON compresses every field onto a single line regardless of how deeply nested it is, hiding the actual structure. Formatting adds indentation that matches each fieldâs nesting depth, making parent-child relationships visually obvious.
What is the difference between formatting JSON and validating it?
Formatting improves readability through indentation and spacing. Validating checks whether the JSON actually follows correct syntax rules. A file can be nicely formatted and still be invalid, which is why the two are separate steps.
Formatting JSON is one of those small, unglamorous skills that ends up saving real time constantly, whenever you are debugging an API, inspecting a config file, or trying to make sense of data someone else handed you. Once you know the process, it takes seconds rather than the minutes you would otherwise spend squinting at a compressed line trying to mentally reconstruct its structure.
None of the steps in this guide require special tools beyond a browser, and the same process works whether you are formatting a five-field object or a response with hundreds of nested entries. The only real variable is which specific context you are working in, and the sections above cover the ones that come up most often.
Have some JSON that needs formatting right now? Try ToolMatoâs
JSON Formatter and paste it in.