Skip to content
MyToolkit.pro

Code & Data

JSON Formatter

Paste JSON to validate it and produce a readable, consistently indented document.

Private by design: JSON is processed only in this browser.

Output options

Try an example

Formatted JSON

Lines
0
Characters
0

Data tree

How formatting works

The browser parses the document as JSON and serializes it again with two-space indentation. Invalid syntax is reported without uploading the input.

Formatting and validating JSON step by step

  1. Paste your JSON into the JSON input field, drop a .json file onto it, or use "Load from file" (files up to 2 MB). The buttons under "Try an example" load a sample.
  2. The output refreshes while you type. The Format JSON button runs the same check on demand and moves the cursor back into the input if the JSON is invalid.
  3. With no option ticked you get two-space indentation. Tick Minify output to remove indentation and line breaks (spaces inside strings stay), or tick "Sort object keys recursively" to reorder the keys of every object.
  4. Read the result under Formatted JSON. The "Lines" and "Characters" counters describe the output, not your input. Below it, the "Data tree" shows each object and array as a collapsible row with its item count, and the first two levels start expanded.
  5. Click Copy result to put the output on your clipboard, or "Download result" to save it as a file. "Clear" empties the input and also unticks both options.

Examples: beautify, sort, minify

The built-in "Nested object" example, pretty-printed:

{"user":{"name":"Alice","roles":["admin","editor"]}}

becomes 9 lines and 91 characters:

{
  "user": {
    "name": "Alice",
    "roles": [
      "admin",
      "editor"
    ]
  }
}

With key sorting on, keys are reordered at every level, but array items stay in their original order:

{"z":{"b":2,"a":1},"a":[{"d":4,"c":3}]}
{
  "a": [
    {
      "c": 3,
      "d": 4
    }
  ],
  "z": {
    "a": 1,
    "b": 2
  }
}

Keys are sorted in your browser's alphabetical order, so lowercase and uppercase letters are not split into separate groups (a, b, B). The exact position of accented letters follows your browser's language settings. Keys made only of digits (no leading zero or minus sign) come first, in numeric order (9 before 10); keys such as 01 or -1 are sorted as text. The order can therefore differ from jq -S or Python's sort_keys, which sort by character code.

Minifying goes the other way. An indented document such as { "z": 1, "a": [3, 1] } spread over four lines becomes {"z":1,"a":[3,1]}: one line, 17 characters.

What the validator rejects

The tool accepts strict JSON as defined in RFC 8259 and nothing looser. Many "why is my JSON invalid" questions come from syntax that JavaScript or config files allow but JSON does not:

Input Why it fails
{'a':1} Keys and strings must use double quotes
{"a": 1,} No trailing comma after the last item
{"a":1} // note Comments are not part of JSON
{a:1} Keys must be quoted strings

When a document fails, the output stays empty and a red message appears under the input. In Chrome, Edge and other Chromium browsers the message usually also gives a line and column. For example, the trailing comma in a three-line object {, "a": 1,, } is reported at line 3, column 1, where the parser expected another key. Use the line numbers in the input's left gutter to find the spot.

A valid document can still come out different from what you pasted, because the tool re-serializes the parsed value instead of only re-indenting your text:

  • Numeric keys: keys made of digits only (such as "1" or "42") are moved to the start of their object, in numeric order, even without sorting. {"b":1,"1":2,"a":3} becomes "1", "b", "a".
  • Large integers: numbers are read as 64-bit floating point, so integers longer than about 15–16 digits are rounded. {"id":12345678901234567890} becomes "id": 12345678901234567000. If long IDs must stay exact, keep them as strings.
  • Duplicate keys: {"a":1,"a":2} is accepted without an error and becomes "a": 2. Only the last value is kept.
  • Notation: 1.10 becomes 1.1, and escapes such as \u00e9 are written out as é.

A bare value such as "just a string" or 42 is valid JSON and is returned unchanged.

Typical uses

  • Reading an API response: paste a minified body from your browser's network tab or from curl, then collapse the parts you don't need in the tree.
  • Comparing two payloads: format both with key sorting on, then paste them into Text Diff / Compare. With the keys in the same order, the diff shows only real changes in values.
  • Preparing config or fixtures: minify JSON before putting it in an environment variable or a one-line test fixture, or beautify it before committing so code reviews are readable.
  • Checking hand-edited files: load a package.json or a translation file to find the stray comma before your build fails.

Limits and when to use another tool

Everything runs in your browser, so the practical limit is your device's memory. Typed or pasted text is capped at 1,000,000 characters, and files loaded from disk can be up to 2 MB. The text output always contains the full document, but the Data tree stops after 1,000 nodes and shows a notice.

If you need rows and columns instead of a nested document, convert an array of objects with JSON to CSV. If your config is in YAML, or you want to convert between YAML and JSON, use the YAML Formatter & Converter.

Frequently asked questions

What is the difference between a JSON formatter and a JSON validator?

A validator only tells you whether the text is valid JSON; a formatter rewrites valid JSON with consistent indentation. This tool does both in one pass.

Can this tool fix invalid JSON automatically?

No. It reports the problem and leaves your input as it is. The table of rejected syntax above lists the usual fixes.

Can I format JSON with tabs or four spaces?

No. Indentation is fixed at two spaces, and the only alternative is minified output on one line.

Does sorting keys change the meaning of my JSON?

No. JSON objects are unordered, so reordering their keys doesn't change the data. Arrays are ordered, and the tool leaves array items where they are.

All in Code & Data

YAML Formatter & Converter

Format YAML, convert YAML to JSON and JSON to YAML in your browser. Nothing is uploaded.

Code & Data In your browser

JWT Decoder

Decode a JSON Web Token (JWT) in your browser. Read the header and payload claims, see the algorithm and claim count. Nothing is uploaded and the signature is not verified.

Code & Data In your browser

JSON to CSV

Convert a JSON array of objects to CSV in your browser. Choose the delimiter, keep or drop the header row, with correct quoting. Nothing is uploaded.

Code & Data In your browser

CSV to JSON

Convert CSV to a JSON array in your browser. Choose the delimiter, use the first row as keys, pretty-print or minify, with RFC 4180 quoting. Nothing is uploaded.

Code & Data In your browser

Regex Tester

Test a regular expression against your text, see every match highlighted and copy a match report. Runs entirely in your browser.

Code & Data In your browser

Hash Generator

Generate MD5, SHA-1, SHA-256 and SHA-512 hashes of any text in your browser. Digests update instantly and nothing is uploaded.

Code & Data In your browser

What do you need?

Swipe up for the next one