MultiTools
Text & Data

JSON Formatter

Format, validate and minify JSON instantly.

  • Local by default
  • No signup
  • AI is opt-in

Output

 

Paste JSON to validate it, pretty-print it, minify it or sort its keys. Errors are reported with a line and column instead of a character offset, and the whole document stays in your browser — which matters when the payload contains customer data or API keys.

What is and is not valid JSON

JSON is defined by RFC 8259 and is deliberately strict. Keys must be double-quoted, strings cannot span lines, trailing commas are illegal, and NaN and Infinity are not values. Comments are not part of the specification either.

Two extensions cause most confusion. JSON5 allows single quotes, unquoted keys, comments and trailing commas. JSONC allows comments and trailing commas, which is why tsconfig.json and VS Code settings accept files that JSON.parse rejects. If a parser refuses a config file that looks fine, check the extension rather than your syntax.

Reading a parse error without guessing

V8 error messages include a character position, and newer versions add a line and column. This tool converts the position into a line and column for you, because counting characters is not a productive debugging strategy. Start at the reported token and look backwards: the actual mistake is almost always just before where the parser gave up.

  1. A trailing comma before } or ] — valid in JavaScript, invalid in JSON.
  2. Single quotes around keys or strings.
  3. An unquoted key such as {id: 1}.
  4. A stray comma after the last array element produced by a template loop.
  5. Smart quotes or a BOM copied from a document.

Big integers lose digits silently

JSON has one number type, and JavaScript parses it as an IEEE 754 double. Integers above 253 − 1 cannot be represented exactly, so a 19-digit identifier can change value the moment it is parsed. The formatter then prints the rounded number, and nothing in the output warns you.

JSON.parse('{"id": 9007199254740993}').id
// 9007199254740992 — the last digit is gone

JSON.stringify({ id: 9007199254740993 })
// {"id":9007199254740992}

A reviver cannot fix this: it runs after parsing, when the original digits are already lost. Keep large IDs as strings at the API boundary, quote them in the payload, or use a lossless parser that reads numbers as raw text. The same applies to balances in minor units once they exceed the safe integer range.

Formatting, minifying and sorting

Formatting adds whitespace for humans; the parsed value is identical. Minifying removes that whitespace to reduce bytes on the wire, though with gzip or brotli the saving is far smaller than the raw difference suggests — minify for consistency, not for bandwidth. Sorting keys rewrites objects alphabetically at every level, which makes diffs stable in version control. It does not change semantics, but it does change key order for anything that iterates naively, so avoid it on payloads where order is meaningful.

Formatting then minifying is not guaranteed to reproduce the original byte-for-byte. Duplicate keys are collapsed (last value wins), number formatting can change (1.0 becomes 1), and escapes may be rewritten.

How large a file can it handle?

The browser holds the text and the parsed object in memory simultaneously, so practical limits are roughly 50–100 MB on a modern laptop. Beyond that, a streaming tool is the right answer: parsing a 1 GB JSON file into an object graph is not something any browser should do.

When to use jq instead

A browser formatter is convenient for inspection; a terminal is better for automation and for files that would make a tab sluggish. jq formats, minifies, sorts keys and streams input instead of holding one giant object graph. If a payload is hundreds of megabytes, use jq or a streaming parser rather than raising the limits here.

jq . response.json          # pretty-print
jq -c . response.json       # minify
jq -S . response.json       # sort keys
jq empty response.json      # exit non-zero if invalid

Validation versus schema validation

This page checks that the document is syntactically valid JSON. It does not check that the shape is what your API expects — a payload can be perfectly valid JSON and still be missing a required field. Shape validation needs a JSON Schema validator, and belongs in your test suite or at the API boundary, not in a browser formatter.

Parsing is safe; merging is not

JSON.parse does not execute code. A payload containing __proto__ becomes an ordinary own property, so parsing alone is not prototype pollution. The danger starts when parsed keys are assigned onto another object — through Object.assign, a recursive deep-merge, or a helper that copies keys with bracket assignment.

If a payload is untrusted, validate its shape, reject keys such as __proto__, constructor and prototype, and build a new object with explicit fields instead of copying arbitrary keys. Size is the other boundary: a deeply nested document can exhaust the call stack in recursive code even when parsing succeeds.

Frequently asked questions

Is my JSON uploaded anywhere?

No. Parsing and formatting happen in JavaScript in your browser. There is no upload endpoint, and the input is not persisted or logged. You can confirm with the browser network panel: no requests are made while you type or click.

Why does my JSON fail to parse when it looks correct?

The most common reasons are a trailing comma, single quotes, an unquoted key, or a comment. All four are valid JavaScript but invalid JSON. The error message here includes a line and column to point at the exact token.

Can this tool convert JSON to CSV or TypeScript?

This page focuses on validation and formatting. For TypeScript, use the JSON to TypeScript tool on this site: it turns a sample into interfaces, type aliases or Zod schemas. CSV remains out of scope here, because arrays of objects map cleanly but nested objects do not.

Does sorting keys change the data?

No. Key order is not significant in JSON, so the parsed value is unchanged. The visible bytes change, which is the point: stable key order makes version-control diffs readable.

What is the maximum file size?

There is no hard limit in the code, but parsing holds both the text and the object in memory. Around 50–100 MB is a realistic ceiling on a desktop browser before the tab becomes sluggish.

Why did my 19-digit ID change after formatting?

JavaScript parses JSON numbers as IEEE 754 doubles, which cannot represent every integer above 2^53 − 1 exactly. The digit is rounded during parsing, before any formatter sees it. Keep large identifiers as strings in the API response, or use a lossless parser that reads numbers as raw text.

Is it safe to parse JSON from an untrusted source?

Parsing itself is safe: JSON.parse does not execute code, and a __proto__ key becomes an ordinary property. The risk appears when the parsed object is merged or assigned onto another object. Validate the shape, reject dangerous keys, and never deep-merge untrusted input into application state.