Skip to content
Kilnfile

JSON Formatter

Validate JSON, pretty print it with your chosen indentation, sort keys or minify it.

Processed on your device, nothing uploadedLast updated

To format JSON, paste it into the Input box, choose 2 spaces, 4 spaces, Tab or Minified under Indentation and click Format JSON; the formatted result appears in the output panel. If the JSON is invalid, the tool shows the line and position of the error instead. Everything runs in your browser, so no data is uploaded.

Your file stays in this tab.On your device
Options

How do I format and validate JSON?

  1. Paste your JSON into the Input box; a raw API response, a config file or a single line all work.
  2. Choose the Indentation: 2 spaces, 4 spaces, Tab or Minified (no whitespace).
  3. Tick Sort keys alphabetically if you want every object's keys in A to Z order.
  4. Click Format JSON. If there is a syntax error, the message tells you the line and position to fix.
  5. Click Copy output to copy the formatted JSON, or Download to save it as a .json file.

The formatter parses your text with the browser's own JSON parser, the same one that runs inside every website, so if it passes here it will pass anywhere. It then rewrites the structure with the indentation you chose. Two spaces is the default and what most JavaScript projects, npm and GitHub use; four spaces suits Python and .NET codebases; tab indentation is preferred by some teams because it lets each editor decide the width. Minified strips every unnecessary space and line break, which typically cuts a formatted file by 30 to 50% and is what you want before embedding JSON in a URL or a data attribute.

Validation is where the tool earns its keep. A trailing comma after the last item, single quotes instead of double, an unquoted key, a comment, or a stray NaN are the usual culprits, and each is reported with a line number and character position so you can go straight to it. Note that JSON is stricter than JavaScript: comments and trailing commas are never allowed, however common they are in config files.

Sort keys alphabetically reorders the keys of every object at every depth while leaving arrays in their original order, because array order carries meaning. Sorted output makes two versions of a file far easier to compare in the Diff Checker, and it makes generated JSON stable between runs. Key order does not affect how any parser reads the data.

Everything runs as plain JavaScript in your browser tab, so your API keys, customer exports and internal configs never leave your machine and nothing is stored. Files of several megabytes format in under a second; beyond a few tens of megabytes the browser textarea itself becomes the limit rather than the formatter.

How it works: this tool uses plain JavaScript running in your browser tab. No server is involved, so Kilnfile never sees your file. Last reviewed 20 September 2026.

Frequently asked questions

Why does my JSON say it is invalid when it looks fine?

The most common causes are a trailing comma after the last item in an object or array, single quotes around strings or keys, a missing comma between items, or a comment. The error message gives the line and position, and the problem is usually on that line or the one just before it.

Should I use 2 spaces or 4 spaces?

It only affects readability, not validity. Two spaces is the JavaScript and web convention and keeps deeply nested data narrower; four is common in Python, Java and C# projects. Use whatever your team's existing files use.

What does minify do and when should I use it?

Minify removes all spaces, tabs and line breaks that are not inside strings, giving the smallest valid JSON. Use it for data sent over the network, stored in a database column or embedded in HTML. Formatting and minifying never change the data itself.

Does sorting keys change the meaning of the JSON?

No. Objects in JSON are unordered by specification, so any parser treats sorted and unsorted versions identically. Arrays are left in their original order because their order does matter. Sorting is mainly useful for comparing files or keeping generated output consistent.

How large a file can I format?

Several megabytes is comfortable and finishes in well under a second. Very large files of tens of megabytes will still work but the textarea becomes slow to scroll, so for those a command-line tool is quicker. Nothing you paste is uploaded; the formatting runs in your browser tab.

Cite this page: “JSON Formatter: Validate, Pretty Print and Minify JSON”, Kilnfile, https://kilnfile.com/text/json-formatter/

Guides