Skip to content
HandyKit

JSON Formatter

Paste or open JSON to pretty-print it, explore it as a tree, or repair almost-JSON. Errors are pinpointed by line and column, with a suggested fix.

Runs in your browser. Your input is never uploaded or stored.

This is example JSON. Paste yours to replace it.

27 lines, 410 bytes

What is JSON?

JSON (JavaScript Object Notation) is a plain-text format for structured data, defined by RFC 8259. It is the usual format for REST API requests and responses, configuration files such as package.json, structured logs, and document databases.

A JSON document is built from six kinds of value: objects ({ }), arrays ([ ]), strings in double quotes, numbers, true and false, and null. Whitespace between values has no meaning, which is why the same data can be minified onto one line or spread across many lines to be readable.

How to format JSON

  1. Paste your JSON into the input, select Open file, or drop a file onto the editor. Files are read on your device, not uploaded.
  2. Choose an indentation: 2 spaces, 4 spaces or tabs.
  3. Select Format, or press Ctrl + Enter (⌘ + Enter on Mac). The formatted result appears next to the input.
  4. If the input has a syntax error, it is underlined as you type, and the message shows its line and column with a suggested fix. Show in input moves your cursor to it.
  5. Select Copy to put the result on your clipboard, or Download to save it as a file.

Before and after

Minified JSON from an API response:

{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true,"last_login":null}

The same data after formatting with 2 spaces:

{
  "id": 42,
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  },
  "active": true,
  "last_login": null
}

What this formatter changes, and what it doesn't

Only whitespace changes. Many online formatters work by running JSON.parse and then JSON.stringify, which quietly alters data on the way through:

  • Integers larger than 9,007,199,254,740,991 are rounded. 12345678901234567890 comes back as 12345678901234567000, which breaks IDs from systems like Twitter/X, Discord and many databases.
  • Numbers are rewritten: 1.50 becomes 1.5 and 1E3 becomes 1000.
  • Escape sequences are decoded: "café" becomes "café".
  • When a key appears twice in an object, only the last value is kept.

This tool reads your JSON with its own parser and keeps the original text of every string and number, so none of that happens. If your data contains a duplicate key or an integer that JavaScript can't store exactly, you'll see a note under the result, because other software reading the same JSON may handle it differently.

Repairing almost-JSON

JSON copied from code, logs or chat often isn't quite valid. Repair fixes the common problems and lists every change it made, with its line and column:

  • Comments (//, /* */ and #) and trailing commas are removed.
  • Single-quoted and curly-quoted strings get straight double quotes.
  • Unquoted property names are quoted, and missing commas between items are inserted.
  • Python and JavaScript values become JSON: True to true, None, NaN and undefined to null.
  • Numbers like +5, .5 and 0x1F are rewritten as 5, 0.5 and 31.
  • Wrappers are removed: JSONP callbacks such as callback({...}), Markdown code fences, and const config = {...}; assignments.

For example, this JavaScript object:

const settings = {
  // UI options
  theme: 'dark',
  plugins: ['git', 'lint',],
  experimental: undefined,
};

repairs to valid JSON:

{
  "theme": "dark",
  "plugins": [
    "git",
    "lint"
  ],
  "experimental": null
}

Repair never guesses. A number with leading zeros such as 02134 is left alone, because it may be a ZIP code or ID that should be a string. Format and Minify never repair anything: they stop at the first error so you can see it.

Exploring JSON as a tree

Select the Tree tab to browse the result as a collapsible tree. Use the arrow keys to move and expand, or Find in tree to highlight every matching key and value. Select any row to see its JSONPath, such as $.tools[0].slug, and copy the path or the value. Large numbers are shown exactly as written, not rounded.

Common JSON errors and how to fix them

Trailing comma

{"a": 1, "b": 2,} is invalid. JavaScript allows a comma after the last item, JSON does not. Remove the comma before the closing } or ].

Single quotes

{'name': 'Ada'} is invalid. JSON strings and property names must use double quotes: {"name": "Ada"}. This often happens when pasting a Python dictionary or a JavaScript object.

Unquoted property names

{name: "Ada"} is a valid JavaScript object but not valid JSON. Wrap every property name in double quotes.

Missing comma

{"a": 1 "b": 2} needs a comma between the two properties. The error points at the start of the property after the missing comma.

Comments

JSON has no comment syntax, so // and /* */ are errors. Formats such as JSONC and JSON5 allow comments, but a standard JSON parser will reject them.

Values from other languages

True, False and None (Python) and NaN, Infinity and undefined (JavaScript) are not JSON values. Use true, false and null, or store special numbers as strings.

Leading zeros

{"zip": 02134} is invalid because JSON numbers can't start with a zero. If the leading zero matters, as in ZIP codes, phone numbers and IDs, store the value as a string: "02134".

Line breaks inside strings

A string must be on one line. Write a line break as \n instead of pressing Enter inside the quotes. This error also appears when a closing quote is missing.

Choosing an indentation style

Two spaces is the most common choice for JSON: it is what JSON.stringify(data, null, 2) produces and what npm uses for package.json. Four spaces is common in Python projects, since json.dumps(data, indent=4) appears in many examples. Tabs keep files smaller and let each reader choose how wide an indent looks.

If your project has a formatter such as Prettier or an .editorconfig file, match it, so formatted JSON doesn't create noise in code reviews. For data that is sent over the network rather than read by people, use Minify to remove whitespace altogether.

Frequently asked questions

Is my JSON uploaded or saved anywhere?

No. Formatting runs in JavaScript inside this browser tab, and opening a file reads it on your device. Your input is not sent to a server, logged, or kept in browser storage, so it is gone when you close the tab. Once the page has loaded, the tool keeps working even if you go offline.

Will formatting change my data?

Only whitespace changes. Strings, escape sequences, numbers and key order stay exactly as you wrote them, including integers too large for JavaScript to store exactly. The one optional change is "Sort keys A to Z", which reorders object keys but never their values.

What does Repair fix?

Repair turns almost-JSON into valid JSON: it removes comments and trailing commas, converts single and curly quotes, quotes unquoted property names, inserts missing commas, replaces Python and JavaScript values such as True, None, NaN and undefined, and unwraps JSONP callbacks, code fences and "const x =" assignments. Every fix is listed with its line and column, so you can check it.

What will Repair not change?

Anything where the right fix is a guess. Numbers with leading zeros, such as 02134, are left for you to decide, because the value may be an ID or ZIP code that should be a string. Formatting and Minify never repair anything: they report the first error instead.

How are keys sorted?

By Unicode code point, at every level of nesting. That puts uppercase letters before lowercase ones ("Zebra" sorts before "apple"), which matches how most programming languages compare strings. Arrays keep their original order.

How large a file can I format?

Files up to 100 MB can be opened. Inputs over 256 KB are processed in a background thread, so the page stays responsive, and the editor only draws the lines on screen. Very large files still depend on your device’s memory.

Guides

  • · 2 min read

    How to Compare Two JSON Files

    Find what changed between two JSON documents, ignoring key order and formatting. A worked example, how to read JSONPath, and how arrays and numbers compare.

  • · 2 min read

    How to Convert JSON to CSV, YAML or XML

    Turn JSON into a CSV spreadsheet, YAML or XML, with worked examples showing how nested objects, arrays and null values are handled, and how to open it in Excel.

  • · 2 min read

    Minify JSON: What It Does and When to Use It

    What minifying JSON removes, what it never changes, when it is worth doing and when it is not, and why sorting keys gives stable output you can compare or hash.

  • · 4 min read

    Common JSON Errors and How to Fix Them

    Trailing commas, single quotes, comments, True and None: the JSON syntax errors developers hit most often, what each error message means, and how to fix it.