{ }

JSON Formatter

✓ Free & no signup 🔒 Runs 100% in your browser Updated 2026-11-25 Development Tools

JSON is the lingua franca of APIs, config files, and logs, and it is also famously unforgiving: one stray comma and the entire document refuses to parse, with a browser error message that often points nowhere useful. This formatter fixes that workflow. Paste your JSON and you can format it with readable indentation, minify it down to a single line, or validate it and get the exact line and column of the first syntax error.

Everything runs locally in your browser. Your JSON, whether it is an API response, a config file with secrets, or a data export, is parsed in the tab and never sent to any server. There is no signup, no size gate beyond your device's memory, and it works equally well on mobile and desktop.

Beyond the three main actions, the tool includes a collapsible tree view for exploring nested data visually, a copy button, a download button for saving the formatted result, and a sample JSON button that loads a realistic example so you can experiment before pasting real data.

What Is JSON and Why Does It Break So Easily?

JSON, short for JavaScript Object Notation, has a deliberately tiny grammar. Objects are key-value maps in curly braces, arrays are ordered lists in square brackets, and the only legal value types are strings, numbers, true, false, null, objects, and arrays. The strictness is the trap. Keys must be double-quoted strings. Strings must use double quotes, not single quotes. Trailing commas after the last item of an object or array are forbidden. Comments do not exist in JSON. Numbers cannot be written as NaN or Infinity.

Because every byte matters, a document that renders as 2000 lines of nested data can be invalidated by a single character. The most frequent offenders, in rough order of how often they appear in real-world debugging:

  • A trailing comma after the final item, for example a comma following the last key-value pair before a closing brace.
  • Single quotes around keys or strings, usually copied from JavaScript or Python code.
  • Unquoted keys, another JavaScript habit that JSON rejects.
  • Comments, which are valid in many config formats but not in JSON.
  • Smart curly quotes pasted from word processors or chat windows instead of straight double quotes.
  • A missing brace or bracket somewhere deep in the nesting, so the parser runs out of input before the structure closes.

How to Use the Formatter (Step by Step)

  1. Paste your JSON into the input area, or click the sample JSON button to load an example document and see how the tool behaves.
  2. Click Validate first if the JSON came from an unknown source. If the syntax is broken, the error is reported with its line and column position in the original text.
  3. Choose your indentation: 2 spaces, 4 spaces, or a tab. The 2-space style is the most common convention in modern tooling.
  4. Click Format to pretty-print, or Minify to strip all unnecessary whitespace for transport or storage.
  5. Use the tree view to explore the structure: objects and arrays collapse and expand, and every value is shown with its type.
  6. Copy the result to the clipboard or download it as a file when you are happy with it.

Format, Minify, and Validate: What Each Mode Does

ModeWhat it doesTypical effect
FormatPretty-prints with your chosen indentation, one key per lineA 2.4 KB config becomes readable and diff-friendly
MinifyRemoves all non-essential whitespace and line breaksThe same file typically shrinks 25 to 35 percent, for example 2.4 KB to about 1.6 KB
ValidateParses the text without altering it and reports the first syntax errorA precise line and column pointer instead of a vague failure

Formatting and minifying never change your data. Keys, values, and their order are preserved exactly; only whitespace between tokens differs. Key order is not sorted alphabetically, which matters when a consumer of the JSON depends on insertion order, as some logging and hashing tools do.

Reading the Tree View

Nested JSON is hard to read as text: an API response with three levels of objects and arrays turns into a wall of braces. The tree view renders the same data as a collapsible hierarchy. Arrays show their length next to the bracket, objects show their key count, and leaf values display with their type visible at a glance, so a string, a number, and a null are never confused. Click any object or array to fold its entire subtree into a single line. This is the fastest way to answer questions like what keys does this response actually contain or where is that nested field I need.

How Error Positions Are Calculated

Under the hood the tool calls the browser's JSON.parse, which stops at the first syntax error it meets. The raw parser error reports a character offset; the formatter converts that offset into a line number and a column, counting lines the way text editors do, starting at line 1 column 1. Two practical notes: fix the first reported error and re-validate rather than trying to fix everything at once, because a single missing brace can cascade into several misleading downstream complaints. And remember that an error at line 40 is sometimes caused by an unclosed bracket that opened at line 12; the reported position is where the parser gave up, not necessarily where the mistake lives.

JSON vs JavaScript Object Literals

The similar names cause endless confusion. A JavaScript object literal, the thing you write inside a .js file, allows comments, unquoted or single-quoted keys, trailing commas, and shorthand values. JSON allows none of these. If your formatting fails right after you copy config out of a JavaScript file, look for those four habits first. Conversely, any valid JSON is also a valid JavaScript expression, which is why JSON works so naturally in that ecosystem. One subtle detail: JSON.parse silently keeps the last occurrence of a duplicated key, so two identical keys in one object are not reported as errors; if duplicate keys matter for your data, search the text for them manually.

Tips and Best Practices

  • Keep a formatted master copy of any JSON you edit by hand, and minify only at build or deploy time. Diffing minified one-line JSON is nearly impossible.
  • Prefer 2-space indentation for shared files; it is the de facto standard in most modern repositories and tooling.
  • Validate API responses before debugging your own code. Far too many bugs blamed on application logic are actually a 500 error page or an HTML string pretending to be JSON.
  • Use the download button to save formatted output for code review, then diff it against the previous version.
  • For very large payloads, tens of megabytes or more, expect the tree view to get slow; browsers hold everything in memory. Multi-hundred-megabyte JSON belongs in command-line tools, not a browser tab.

Frequently Asked Questions

Why does my JSON fail validation even though it looks correct?
The usual culprits are invisible or nearly invisible characters. Check for a trailing comma after the last item in an object or array, single quotes where JSON demands double quotes, unquoted keys copied from JavaScript, and curly smart quotes pasted from a word processor or chat app. Comments are another frequent surprise: they are legal in many config formats but not in JSON. The tool's line and column report tells you exactly where parsing stopped, which is usually one or two characters past the real mistake.
Does formatting or minifying change my data?
No. Both operations only adjust whitespace between tokens: formatting adds indentation and line breaks for readability, minifying removes them for compactness. Every key, value, string, number, and their order is preserved exactly as written. One nuance to know: formatting does normalize nothing inside strings, so if a string value contains escaped characters, they stay escaped. The safe habit is to format freely and compare, since the parse step itself guarantees the data survived; if the text parses, formatting cannot have altered any value.
Does the formatter sort keys alphabetically?
No. Key order is preserved exactly as it appears in your input, because JSON objects are semantically unordered but many real-world tools depend on the original order: some logging systems, signature schemes, and snapshot tests compare serialized text where reordering keys would break them. If you genuinely need alphabetical keys for comparison purposes, do it in a script with a sorting step rather than trusting a formatter, since a formatter's job is to change presentation, never your data's structure or ordering.
What does the line and column in an error message mean?
When parsing fails, the tool converts the parser's character offset into a line number and a column within your pasted text, counting from line 1, column 1 at the very start. Line 3, column 15 means: go to the third line, count fifteen characters in, and the parser gave up there. The actual typo is often slightly earlier, for example the comma before that position, and a missing closing bracket can make the error appear far from its cause. Fix the first error, re-validate, and repeat until the document parses.
Is my JSON sent to a server?
No. All parsing, formatting, minifying, and tree rendering happens in your browser using JavaScript running in the tab. The text never leaves your device: you can watch the network tab in developer tools while formatting and you will see no requests. That matters because real JSON frequently contains sensitive content, including API keys in config files, customer records in data exports, and authentication payloads from login endpoints. The tool is free, requires no signup, and works offline once the page has loaded.
How large a JSON file can this handle?
There is no hard-coded limit; the practical ceiling is your browser's memory and rendering speed. Documents up to a few megabytes format almost instantly, and the tree view stays responsive to around ten megabytes on a typical laptop. At several tens of megabytes the pretty-printer still works but the tree view becomes sluggish, because rendering tens of thousands of collapsible nodes is expensive. For multi-hundred-megabyte JSON, use command-line tools such as jq instead, and paste in only the section you need to inspect.

Related Tools