JSON 格式化与校验

即时格式化、校验和压缩 JSON,支持语法高亮与精确的错误定位。完全在浏览器中运行,不上传任何数据。

Indentation

Why use a JSON formatter

Malformed JSON is one of the most common causes of failing builds and broken API calls. This tool validates your JSON, pinpoints the exact character where parsing fails, and formats it to your preferred indentation style.

Features

  • Syntax highlighting for keys, strings, numbers, booleans and nulls
  • Error location with line and column numbers
  • Minify mode for production payloads
  • Choose your indentation — 2 spaces, 4 spaces, tabs, or none
  • 100% client-side — your data never leaves your browser

Common JSON errors

ErrorCauseFix
Unexpected tokenTrailing comma or missing quoteRemove the comma before } or ]
Unexpected end of JSON inputUnclosed bracket or braceMatch every { with a }
Invalid escape characterSingle backslash in a stringUse \\ for a literal backslash
Unexpected token in JSONSingle quotes instead of doubleJSON requires double quotes
Bad control characterLiteral newline inside a stringEscape it as \n

The most common mistake

Trailing commas. JavaScript objects allow them, JSON does not:

{
  "name": "toolnest",
  "tags": ["free", "fast"],   <-- this comma is invalid
}

The error message tells you the exact line and column, which is usually enough to find it in a large payload.

Tips for working with large payloads

Most browsers handle a few megabytes of JSON without trouble. If the formatter feels slow, minify the output instead of pretty-printing it.

For very large files in a development workflow, jq on the command line is faster:

jq . data.json          # pretty print
jq -c . data.json       # minify
jq '.users[0].email' data.json

Related

Use the Base64 encoder to encode the payload for a URL or header, or decode a JSON Web Token to inspect its claims.

常见问题

Is my JSON uploaded anywhere?

No. The entire tool runs in your browser using JavaScript. Your payload is never sent to a server.

Can it handle large JSON files?

Yes, up to a few megabytes. For very large files, pretty-printing may feel slow but still works.

How do I fix a trailing comma error?

Delete the comma that appears immediately before a closing } or ]. JSON does not allow trailing commas.

Does it support JSON Lines (NDJSON)?

Yes — paste multiple JSON objects on separate lines and each will be validated and formatted independently.

Why does my valid JavaScript object fail?

JSON is stricter than JavaScript. Object keys must be double-quoted, single quotes are not allowed, comments are not allowed, and trailing commas are invalid.