---
title: "JSON formatter & validator"
canonical: "https://devtools.nicxon.tech/tools/json-formatter/"
source: "https://devtools.nicxon.tech/tools/json-formatter/"
generator: devtools.nicxon.tech
---

# JSON formatter & validator

> Pretty-print or minify JSON and get the exact line and column of any syntax error.

## What this does

This tool parses JSON and re-serializes it with consistent indentation, or
 collapses it to a single line. Parsing uses the browser's native
 `JSON.parse`, so "valid here" means "valid to every standards-
 compliant JSON parser". If parsing fails, the error is translated from a
 raw character offset into a **line and column** so you can
 find the problem without counting characters. An optional pass sorts object
 keys recursively, which is handy when you want to diff two documents that
 contain the same data in a different order.

Everything runs in your browser. A 4,000-line configuration file, an API
 response with customer records, or a service-account key can be pasted here
 without any of it being transmitted — there is no server to transmit it to.

## When you'd use it

- Making a minified API response readable while debugging.
- Pretty-printing a JSON string that was logged on one line.
- Checking whether a hand-edited config file is still valid before you deploy it.
- Minifying a JSON fixture to embed it in a source file or a URL.
- Normalising key order so `git diff` on two JSON files shows only real changes.

## Worked example

Paste this (note the trailing comma):

```
{"service":"auth","retries":3,"hosts":["a","b",],"debug":false}
```

The tool reports: `Unexpected token ] — line 1, column 44`.
 Column 44 is the `]`; the character before it is a comma with no
 value after it. Remove the comma:

```
{"service":"auth","retries":3,"hosts":["a","b"],"debug":false}
```

With indent set to 2 spaces, the output becomes:

```
{
  "service": "auth",
  "retries": 3,
  "hosts": [
    "a",
    "b"
  ],
  "debug": false
}
```

Switching indent to *Minify* returns the compact form, now with the
 comma fixed, at 60 bytes.

## Limits and gotchas

- **Strict JSON only.** No comments, no trailing commas, no single quotes, no unquoted keys, no `NaN` or `Infinity`. Those are JSON5 or JavaScript object literals, not JSON.
- **Number precision.** Integers beyond 2^53 and high-precision decimals are rounded to the nearest double on parse. Carry those as strings.
- **Key order.** Re-serialization preserves insertion order unless you enable "Sort keys". Duplicate keys in the input are collapsed to the last value, per `JSON.parse` behaviour.
- **Very large documents.** Formatting is synchronous. Tens of megabytes of JSON will briefly block the tab while it parses.
- **Not a schema validator.** This checks syntax, not whether your document matches an expected shape. Use a JSON Schema validator for that.

## How to use

- **Paste your JSON** — Paste or type JSON into the input box. Formatting runs as you type.
- **Choose an indent** — Pick 2 spaces, 4 spaces, a tab, or Minify to strip all whitespace.
- **Read the result** — The formatted JSON appears on the right with a byte count, or an error message with the exact line and column if the JSON is invalid.
- **Copy or fix** — Copy the output, or jump to the reported line and column to fix the syntax error.

## Frequently asked questions

### Why does it say “Unexpected token” with a line and column?

That is a JSON syntax error at that position. The most common causes are a trailing comma after the last item in an object or array, a single quote used instead of a double quote, an unquoted key, or a missing comma between two items. Go to the reported line and column and check the character just before it.

### It rejects my JSON that has comments — is that a bug?

No. The JSON specification does not allow comments, and this tool validates strict JSON. Files like tsconfig.json are actually JSONC (JSON with Comments), which is a different format. Strip // and /* */ comments before formatting, or use a JSON5/JSONC-aware editor.

### Are my numbers safe from being changed?

Large integers can lose precision. JSON.parse reads numbers into IEEE-754 doubles, so any integer above 2^53 (for example a Twitter-style 64-bit ID) is rounded. If you see a number ending in unexpected zeros, that value should be transported as a string.

### Does “Sort keys” change the meaning of my JSON?

For most consumers, no — object member order is not significant in JSON. It can matter if a downstream system does a naive string comparison of serialized objects, or signs the raw bytes. Sort keys is useful precisely for making two objects comparable, but do not apply it to a payload whose signature was computed over a specific byte sequence.

---
*Source: [https://devtools.nicxon.tech/tools/json-formatter/](https://devtools.nicxon.tech/tools/json-formatter/) — generated by devtools.nicxon.tech.*
