Hunt
Skip to content

JSON Formatter & Validator

Paste JSON to pretty-print it and check that it is valid. If it is not, you get the exact line and column of the first problem and a plain-English explanation. Numbers and strings are copied exactly as you wrote them, so large IDs never lose precision.

Runs in your browser

Input

Paste JSON or press Sample

Formatted

The formatted JSON will appear here

What this JSON formatter does

JSON (JavaScript Object Notation) is the format behind most API responses, configuration files and data exports. It is easy for programs to read and hard for people to read: APIs usually send it minified, on a single line, and one misplaced comma makes the whole document invalid.

This tool does two jobs at once. It validates the text against the JSON standard (RFC 8259) and, if the JSON is valid, re-prints it with consistent indentation so its structure is visible. If the JSON is invalid, it points to the exact line and column of the problem and explains how to fix it. Everything happens in your browser as you type, so it is safe to paste production data, tokens or customer records.

How to use the JSON Formatter & Validator

  1. Paste or type JSON into the input panel, or press Sample to try an example.
  2. The formatted result appears as you type. Choose 2 spaces, 4 spaces or tabs for indentation.
  3. Turn on Sort keys to order object properties alphabetically, which makes two documents easier to compare.
  4. If the JSON is invalid, select the line and column in the error message to jump to the problem in the input.
  5. Copy the result or download it as a .json file.

Examples

Pretty-print compact JSON

Input
{"id":7,"name":"Ada","roles":["admin","dev"],"active":true}
Output
{
"id": 7,
"name": "Ada",
"roles": [
"admin",
"dev"
],
"active": true
}

Format a nested API response

Input
{"data":[{"id":"ord_1","total":4250,"items":[{"sku":"BK-12","qty":2}]},{"id":"ord_2","total":990,"items":[]}],"page":{"next":null}}
Output
{
"data": [
{
"id": "ord_1",
"total": 4250,
"items": [
{
"sku": "BK-12",
"qty": 2
}
]
},
{
"id": "ord_2",
"total": 990,
"items": []
}
],
"page": {
"next": null
}
}

Empty arrays and objects stay on one line, so the shape of the data is easy to scan.

Large numbers are kept exactly

Input
{"orderId":12345678901234567890,"price":19.90}
Output
{
"orderId": 12345678901234567890,
"price": 19.90
}

JSON.parse would turn the ID into 12345678901234567000 and the price into 19.9. This formatter copies both exactly as written.

Sort keys alphabetically

Input
{"b":1,"a":{"d":2,"c":3}}
Output
{
"a": {
"c": 3,
"d": 2
},
"b": 1
}

Keys are sorted at every level. Arrays keep their order, because order in an array is meaningful.

Why values are never changed

This formatter never converts values. It reads the structure of your JSON, then copies each string and number from your original text, so what you paste is exactly what you get back, only indented.

That is not true of most online formatters. They run your text through JSON.parse and JSON.stringify, which converts every number to a JavaScript floating-point value and back, and quietly changes data:

  • Integers above 9,007,199,254,740,991 are rounded: 12345678901234567890 becomes 12345678901234567000. Database IDs, Twitter/X IDs and financial amounts in minor units are common victims.
  • Trailing zeros disappear: 19.90 becomes 19.9, and 1.0 becomes 1.
  • Numbers too large for a double become null: 1e400 is printed as null.
  • Escape sequences are rewritten: \u00e9 becomes é, which matters when you need to see exactly what an API sent.

JSON is not a JavaScript object

JSON looks like JavaScript, and every valid JSON document is also a valid JavaScript expression, but the reverse is not true. Code that works in a .js file often fails as JSON. The differences that cause most errors:

  • Property names must be in double quotes: {"name": 1}, never {name: 1} or {'name': 1}.
  • Strings must use double quotes. Single quotes and template literals are not allowed.
  • No trailing commas after the last item in an object or array.
  • No comments. If you need them, you are probably writing JSONC (used by VS Code and tsconfig.json) or JSON5.
  • Only these values exist: strings, numbers, objects, arrays, true, false and null. There is no undefined, NaN, Infinity, date type or function.
  • Exactly one top-level value. A file with one JSON object per line is JSON Lines (NDJSON), not JSON.

Common errors and how to fix them

Trailing comma

A comma after the last property or array item. JavaScript and JSON5 accept it; JSON does not. It often appears after deleting the last line of an object.

Invalid
{
  "name": "Ada",
  "admin": true,
}
Fixed
{
"name": "Ada",
"admin": true
}

The tool reports: Trailing commas are not allowed in JSON.

Single quotes

Copying a JavaScript or Python object literal usually brings single-quoted strings with it. Replace them with double quotes, and escape any double quotes inside the strings as \".

Invalid
{'name': 'Ada'}
Fixed
{"name": "Ada"}

The tool reports: Strings and property names must use double quotes, not single quotes.

Unquoted property names

Every property name must be a double-quoted string, even when it is a simple word.

Invalid
{name: "Ada"}
Fixed
{"name": "Ada"}

The tool reports: Unexpected "name". Property names and strings must be in double quotes.

Comments

JSON has no comment syntax. Remove the comments, or keep them in a format that supports them, such as JSONC or JSON5. Some teams use a "_comment" property instead.

Invalid
{
  // customer number
  "id": 7
}
Fixed
{
"id": 7
}

The tool reports: Comments are not allowed in JSON.

NaN, Infinity and undefined

These JavaScript values have no JSON equivalent. JSON.stringify writes NaN and Infinity as null and drops properties that are undefined; hand-written JSON has to do the same, or store the value as a string.

Invalid
{"score": NaN}
Fixed
{"score": null}

The tool reports: NaN is not valid in JSON. Use null or a string instead.

Missing comma

Every property and array item must be separated by a comma. This often happens when lines are pasted together.

Invalid
{
  "a": 1
  "b": 2
}
Fixed
{
"a": 1,
"b": 2
}

The tool reports: Expected a comma between values.

Line breaks or tabs inside a string

A string cannot contain a real line break or tab character. Write them as the escape sequences \n and \t.

Invalid
{"note": "first line
second line"}
Fixed
{"note": "first line\nsecond line"}

The tool reports: Invalid character in string. Control characters such as tabs and line breaks must be escaped (\t, \n).

More than one top-level value

A JSON document holds exactly one value. Log files and exports often contain one JSON object per line (JSON Lines). Format each line separately, or wrap the objects in an array and separate them with commas.

Invalid
{"id": 1}
{"id": 2}
Fixed
[
{"id": 1},
{"id": 2}
]

The tool reports: Unexpected content after the end of the JSON value. Only one top-level value is allowed.

Options

Indentation
2 spaces (the most common), 4 spaces, or tab characters.
Sort keys
Orders object properties by name at every level. Array order is never changed, because it is meaningful in JSON.

Limitations

  • Strict JSON only (RFC 8259). Comments, trailing commas, single quotes and unquoted keys are reported as errors; they are allowed in JSON5 and JSONC but not in JSON.
  • The first error is reported. Fix it and the next one, if any, will be shown.
  • Duplicate keys are allowed by the JSON grammar but are reported as a warning, because most parsers silently keep only the last value.
  • Inputs up to 10 MB are supported. Formatting runs in your browser, so very large files depend on your device's memory.

Frequently asked questions

Is my JSON sent to a server?

No. Formatting and validation run entirely in your browser. The JSON you paste is not uploaded, stored or logged, so it is safe to use with API responses and configuration files.

Why does my JSON fail with a trailing comma?

The JSON standard does not allow a comma after the last item of an object or array, as in {"a": 1,}. JavaScript and JSON5 accept it, but JSON.parse and most JSON tools do not. Remove the final comma.

Why are my large numbers changed by other formatters?

JavaScript stores numbers as 64-bit floating point, which can represent integers exactly only up to 9,007,199,254,740,991. Tools that use JSON.parse round larger values. This formatter prints the original text of each number, so nothing is rounded.

Can I use single quotes in JSON?

No. JSON strings and property names must use double quotes. Single quotes are valid in JavaScript object literals and JSON5, but not in JSON.

What is the difference between formatting and validating?

Validating checks that the text follows the JSON grammar. Formatting re-prints valid JSON with consistent indentation and line breaks. This tool always does both: if the input is not valid, it cannot be formatted, and you see why.

How do I format JSON in VS Code or on the command line?

In VS Code, open the file and run Format Document (Shift+Alt+F on Windows and Linux, Shift+Option+F on macOS). On the command line, jq . file.json and python3 -m json.tool file.json both pretty-print JSON. Both parse values first: jq 1.6 and older round large integers, and Python rewrites decimals such as 19.90 as 19.9, so check numbers that matter.