Formatador de JSON

O Formatador de JSON é uma ferramenta online gratuita que permite organizar e validar seu código JSON. Com ele, você pode deixar seus dados mais legíveis e identificar erros de sintaxe rapidamente. Ideal para desenvolvedores e qualquer pessoa que trabalhe com JSON.

Como usar

  1. 1

    Cole seu código JSON na área de texto.

  2. 2

    Clique no botão 'Formatar JSON'.

  3. 3

    Visualize o JSON formatado e validado.

  4. 4

    Copie o resultado para usar em seus projetos.

Perguntas frequentes

Ratings & Reviews

Rate this tool

Sign in to rate and review this tool.

Loading reviews…

What does the JSON Formatter do?

The JSON Formatter takes any JSON string — an API response you copied from a browser tab, a config file, a database row, anything — and either expands it into readable indented form or compresses it onto a single line. It also validates the input: if your JSON has a stray comma, missing quote, or unclosed bracket, the formatter tells you exactly where.

Paste in {"name":"Alice","age":30,"hobbies":["reading","coding"]} and the formatter expands it to:

{
  "name": "Alice",
  "age": 30,
  "hobbies": [
    "reading",
    "coding"
  ]
}

Switch direction and the formatter strips all the whitespace back, producing the compact one-line version. Both run instantly in your browser — there's no server round trip and your data never leaves the page.

When you'll use the JSON Formatter

JSON is everywhere in modern web development, so the formatter shows up in everyday work for several roles:

  • Backend developers debugging API responses — paste a response body from Network tab or a server log to see the structure
  • Frontend developers inspecting payloads received from APIs or webhooks before parsing them in code
  • Data engineers reviewing pipeline outputs, Kafka messages, or NoSQL document records
  • QA engineers diffing expected vs actual responses in test failure reports
  • DevOps reading minified config files (Terraform plans, Kubernetes manifests, GitHub Actions outputs) that arrive in single-line form
  • Anyone working with JSON databases like MongoDB, DynamoDB, or PostgreSQL JSONB columns

The formatter is also useful in reverse: when you need to embed JSON inside another file (a YAML key, a JavaScript string, an HTTP header), minifying the JSON to one line is often required. Both directions are one click.

Validation is the under-appreciated part. The formatter rejects malformed JSON with a precise error pointer — far more useful than the cryptic "SyntaxError: Unexpected token" you'd get in the browser console. If you're trying to figure out why your API call is failing or your config isn't loading, the formatter usually finds the bug in seconds.

How the formatter works

Under the hood, the formatter pipes your input through the browser's native JSON parser. JSON.parse() turns the string into a JavaScript object; JSON.stringify() turns it back into a string with whatever indentation you've chosen. The same APIs every Node.js and browser developer uses, run client-side.

The advantage of using the native parser is correctness: the formatter follows the JSON specification (RFC 8259) exactly. There's no "best effort" parsing — if your JSON has a trailing comma after the last array element, the formatter rejects it, because JSON forbids trailing commas. (JavaScript object literals allow them; JSON does not. This is a common confusion.)

The expansion step uses 2-space indentation by default, which matches the convention used by most JSON-formatted APIs and config files. Individual array elements and object properties each go on their own line, with consistent quoting (always double quotes; never single).

None of this requires server processing — every modern browser parses JSON natively in milliseconds, even for large payloads. The formatter handles single-MB JSON documents without lag.

Common formatting patterns

Different use cases call for different output. Here's how the formatter handles common scenarios:

InputOutput (expanded)Output (minified)
Simple objectMulti-line with indented keysSingle line, no spaces
Array of objectsEach object on its own block of linesSingle line, comma-separated
Deeply nested structureIndentation reflects nesting depthSingle line preserves depth via brackets
Empty objects / arrays{} and [] stay on one lineSame — no whitespace inside
Strings with special charactersEscaped (newlines as \n, etc.)Same escaping; differs in line wrapping
Numbers (int, float, scientific)Preserved as-writtenPreserved as-written

Notice that string content is preserved exactly. If your JSON contains a string with embedded newlines (escaped as \n in the source), the formatter keeps them as-is — it doesn't expand \n into actual line breaks, which would break the JSON.

Numbers also pass through unchanged. JSON allows several number formats (integer, decimal, scientific notation), and the JSON Formatter preserves whichever style was in the input — it doesn't normalize 1e3 to 1000.

Property order in expanded output matches the order in your input. If you paste an object with keys in {name, age, email} order, the formatter outputs them in the same order. JSON specification doesn't actually mandate property order (parsers are free to ignore it), but most stringifiers — including the JSON Formatter — preserve insertion order for readability. If you're working with code that depends on a specific key order, this consistency matters.

Tips and tricks

A few common gotchas when working with JSON:

  • Trailing commas are invalid. [1, 2, 3,] looks fine in JavaScript but breaks JSON. Strip the last comma before pasting.
  • Comments aren't allowed. // note lines and /* block comments */ are JSON syntax errors. Strip them or use JSON5/JSONC if your tool supports them (most don't).
  • Single quotes won't work. JSON keys and string values must use double quotes. {'name':'Alice'} fails to parse.
  • Unquoted keys aren't allowed. {name: "Alice"} is a JavaScript object literal, not JSON. JSON requires quotes around all keys.
  • Numbers can't have leading zeros. 007 is valid in some languages but invalid in JSON. Use "007" as a string if leading zeros matter.

Tip: if you're copying JSON from a browser's Network tab, use "Copy → Copy response" rather than highlighting and copying manually. Manual selection sometimes captures hidden Unicode characters or terminal control codes that break parsing.

Large JSON files (1MB+) work fine in the formatter, but the output gets very long very quickly. If you're trying to inspect a deeply nested structure inside a huge document, consider using a tool that supports collapsing branches — the formatter is best for end-to-end formatting and validation, not interactive exploration of giant documents.

Related developer tools

The JSON Formatter pairs well with several other Microapp dev tools:

  • CSV to JSON Converter — turn spreadsheet data into JSON arrays of objects, ready to format and use as test fixtures or seed data.
  • JSON to CSV Converter — flatten JSON arrays into CSV rows for spreadsheet review or data analysis tools.
  • Base64 Encoder/Decoder — for encoding JSON payloads inside JWT tokens, data URIs, or other base64-wrapped contexts.
  • URL Encoder/Decoder — when you need to safely embed JSON in URL query parameters.
  • Regex Tester — for extracting specific values out of JSON strings when you need a pattern match rather than a parse.

Frequently asked questions

Is my JSON sent to any server?

No. The formatter uses your browser's built-in JSON.parse and JSON.stringify APIs, both of which run entirely client-side. Your data never crosses the network. Closing the tab removes everything.

What's the maximum size of JSON the formatter can handle?

Practically, anything your browser can hold in memory — typically several hundred MB before performance degrades. Multi-MB documents format instantly. Beyond ~50MB you may see brief delays as the browser chunks the work.

Why does the formatter reject my JSON when it looks fine?

The most common causes: trailing commas ([1, 2, 3,]), comments (// note), single quotes instead of double, or unquoted object keys. JSON is stricter than JavaScript object literals — features that work in JS source code aren't always valid in JSON.

Can I customize the indentation (tabs vs spaces, 2 vs 4 spaces)?

The formatter currently uses 2-space indentation, which matches the convention used by most JSON-formatted APIs (Stripe, GitHub, Twilio). If your team uses 4 spaces or tabs, run the output through your code editor's reformatter after pasting.

Does the formatter validate JSON Schema?

No. The formatter validates JSON syntax (does it parse?), not JSON Schema (does it match a specific schema definition?). For schema validation, use a dedicated tool like Ajv or json-schema-validator.

What's the difference between minified and compact JSON?

They're the same thing. "Minified" emphasizes the size reduction (useful for HTTP payloads, gzip ratios); "compact" emphasizes the visual look (single line). Both produce identical output: JSON.stringify(parsed) with no whitespace.

Can the formatter handle JSON5 or JSONC?

No — these are JSON supersets that allow comments, trailing commas, and other relaxed syntax. The formatter follows strict RFC 8259 JSON. To work with JSON5/JSONC, strip the comments and trailing commas first, or use a JSON5-aware tool like the json5 npm package.

Will the JSON Formatter change my data?

It rewrites whitespace only. Object keys, string values, numbers, booleans, and null all pass through unchanged. The expanded and minified outputs parse to identical JavaScript objects — they're equivalent representations of the same data.

Can I use the formatter to validate JSON without changing it?

Yes — paste the input, see whether it parses successfully. If the JSON Formatter accepts your input without an error, the JSON is syntactically valid. (For semantic validation against a schema, use a JSON Schema validator instead.)

Why does the formatter expand my JSON to 2-space indentation specifically?

2-space indentation matches the convention used by most JSON-formatted APIs and developer tools (Stripe, GitHub, Twilio, JSON.stringify's default). It's compact enough to keep deeply nested structures readable without wasting horizontal space, and it's what most code editors expect when reformatting pasted JSON. If your team's style guide differs, run the formatter's output through your editor's reformatter for consistency.