Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

JSON Formatter & Validator (with Error Fixing)

Format, validate and pinpoint syntax errors, even in 50MB+ files.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 B
Runs in your browser. Nothing is uploaded. Tip: click any key in the Tree view to copy its path

How to use the JSON Formatter tool#

  1. Paste JSON into the left box, or drop a .json file onto it. Small inputs are checked as you type; for very large files press Format.
  2. Choose Format (with 2 spaces, 4 spaces or tabs) or Minify. Tick Sort keys to order every object alphabetically.
  3. If the JSON is invalid, read the message under the tool: it gives the line, column and a preview. Press Show me to jump there, or Try to fix to repair comments, trailing commas, single quotes and unquoted keys automatically.
  4. Switch the output to Tree to explore the structure. Click any key to see and copy its JSON path, such as $.users[0].email.

Examples#

Pretty-print minified JSON

Input
{"name":"dev247","tools":["json","base64"],"free":true}
Output
{
  "name": "dev247",
  "tools": [
    "json",
    "base64"
  ],
  "free": true
}

Two-space indentation, one value per line.

Find a trailing comma

Input
{"name": "dev247", "free": true,}
Output
✗ Line 1, column 32: Trailing comma: remove the "," before "}"

Trailing commas are allowed in JavaScript but not in JSON. The most common JSON error.

Fix JavaScript-style JSON automatically

Input
{
  // settings
  name: 'dev247',
  tags: ['a', 'b',],
}
Output
{
  "name": "dev247",
  "tags": [
    "a",
    "b"
  ]
}

Try to fix removed the comment and trailing commas, and quoted the keys and strings.

Minify

Input
{
  "id": 1,
  "tags": ["a", "b"]
}
Output
{"id":1,"tags":["a","b"]}

All unnecessary whitespace removed, ready for an API request or config value.

What is JSON?#

JSON (JavaScript Object Notation) is a text format for structured data: objects in curly braces, arrays in square brackets, and strings, numbers, true, false and null as values. It is the standard format for APIs, configuration files and data exchange, defined in RFC 8259. JSON looks like JavaScript, but its rules are much stricter, which is where most errors come from.

JSON syntax rules#

RuleValidInvalid
Strings use double quotes"name"'name'
Property names are quoted{"id": 1}{id: 1}
No trailing commas[1, 2][1, 2,]
No comments(none)// note, /* note */
Lowercase literalstrue, false, nullTrue, None, undefined
Plain decimal numbers10, -1.5e3010, .5, NaN, 0xFF
Escaped special characters"line\nbreak"a real line break inside a string

How this formatter is different#

Most online formatters run JSON.parse and JSON.stringify. That has two hidden problems: numbers larger than 253 (such as 64-bit IDs from Twitter, Discord or databases) are silently rounded, and the error message often gives no line number. This tool formats JSON token by token instead, so large numbers, key order and even duplicate keys stay exactly as they were, and its own validator reports the exact line and column with a clear explanation.

Sort keys and the Tree view do need to parse the data into JavaScript values. If your JSON contains numbers that would change, the tool tells you.

JSON vs JSON5 and JSONC#

Many config files are not strict JSON. tsconfig.json and VS Code settings use JSONC (JSON with comments), and JSON5 also allows trailing commas, single quotes, unquoted keys and hex numbers. They are convenient for humans but rejected by JSON.parse and most APIs. The Try to fix button reads JSON5 (plus Python's True, False and None) and writes strict JSON.

Format and validate JSON in code#

JavaScript#

javascript
const pretty = JSON.stringify(JSON.parse(text), null, 2);   // formatconst compact = JSON.stringify(JSON.parse(text));           // minify

Command line (jq)#

bash
jq . data.json          # format and validatejq -c . data.json       # minifyjq -S . data.json       # sort keys

Python#

bash
python3 -m json.tool data.jsonpython3 -m json.tool --sort-keys --indent 4 data.json

PHP#

php
echo json_encode(json_decode($json), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); json_validate($json);   // PHP 8.3+: true / false without decoding

Common errors and fixes#

  • Unexpected token } in JSON or "Trailing comma"

    There is a comma after the last item of an object or array. Remove it, or press Try to fix.

  • Unexpected token ' in JSON

    JSON strings and property names need double quotes. Replace single quotes with double quotes, or press Try to fix.

  • Unexpected token / in JSON

    The file contains comments, which JSON does not allow. Remove them, or press Try to fix (common with tsconfig.json and other JSONC files).

  • Unexpected end of JSON input

    The JSON is cut off: a closing } or ] is missing, or the response was empty. Check that you copied everything and that the API actually returned data.

  • Large IDs change after formatting in other tools

    Numbers above 9,007,199,254,740,991 cannot be stored exactly in JavaScript. This tool keeps them exact in the Text view. In your own code, send such IDs as strings.

Frequently asked questions#

How do I find the error in my JSON?

Paste it here. The message under the tool gives the line and column, shows the line with a caret under the problem, and Show me moves the cursor straight to it.

Can this tool fix invalid JSON?

Yes, for the most common problems: comments, trailing commas, single quotes, unquoted property names and Python's True, False and None. Press Try to fix when the JSON is invalid.

How large a JSON file can I format?

Files up to 200 MB can be loaded. Inputs over 2 MB are formatted when you press Format instead of on every keystroke, so typing stays fast.

Does formatting change my data?

No. The Text view only changes whitespace: values, key order, large numbers and duplicate keys stay exactly the same.

What is a JSON path?

A way to point at one value inside a document, such as $.users[0].email. Click any key in the Tree view to see and copy its path for jq, JSONPath or your code.

Is my JSON uploaded?

No. Formatting, validation and the tree view all run in your browser, so it is safe to paste API responses with tokens or personal data.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.