JSON Formatter preview

JSON Formatter

Format, validate, and minify JSON data in your browser. Paste raw JSON and get clean, indented output with syntax error highlighting. Your data stays on your device.

Key features

  • Indent with 2 spaces, 4 spaces or tabs
  • Shows the browser parser error for invalid JSON, with line and column in current browsers
  • Minify & Copy for compact output
  • Colors keys, strings, numbers, booleans, and null

Guide

JSON is the data format that runs the modern web. Every REST API you call returns JSON. Every configuration file in a Node.js project uses JSON. Frontend state, database exports, logging pipelines, serverless function payloads, package manifests, Terraform plans, and CI/CD configs all rely on it. A formatter that also validates saves you from reading one-line payloads by eye.

This tool takes raw or minified JSON and turns it into indented, syntax-highlighted output with 2 spaces, 4 spaces or tabs. Invalid JSON shows the parser error from your browser. You can also copy a minified version of valid JSON. Everything runs in your browser. No data leaves your device.

What JSON Formatting Actually Does

JSON formatting (also called beautifying or pretty-printing) adds consistent indentation and line breaks to a JSON string. A minified API response like {"users":[{"id":1,"name":"Alice","roles":["admin","editor"]},{"id":2,"name":"Bob","roles":["viewer"]}]} becomes a structured tree where each key-value pair sits on its own line and nested objects are indented. The standard indentation is 2 or 4 spaces.

The inverse operation is minification. It strips all whitespace, newlines, and indentation from valid JSON, producing the smallest possible string. Minified JSON transfers faster over networks and takes less storage. How much it saves depends on how deeply the data is nested and how much indentation the original used.

Formatting does not change the data. The parsed JavaScript object is identical whether the JSON string is formatted or minified. The difference is visual, and it is what lets you see the shape of a nested payload.

Under the hood, the formatting process is straightforward. The tool calls JSON.parse() on your input to build an in-memory object tree. If parsing succeeds, it calls JSON.stringify(obj, null, indent) with the indentation you picked (2 spaces, 4 spaces or a tab character). The syntax highlighting layer then colors keys, strings, numbers, booleans, and null, so you can scan the data faster.

How the Validator Works

JSON has strict syntax rules defined in RFC 8259. Strings must use double quotes, not single quotes. Trailing commas after the last element in an array or object are not allowed. Property names must be quoted. No comments are permitted. Numeric values cannot have leading zeros (except 0 itself). The only valid literals are true, false, and null (all lowercase). True, False, TRUE, NULL, and None are all invalid.

When you paste text into the formatter, it runs JSON.parse() internally. If parsing fails, the tool catches the SyntaxError and shows the message your browser produced. Current Chrome and Firefox include the position, and the line and column, of the first character that broke the parse.

Common errors that the validator catches include:

  • Single quotes instead of double quotes: {'name': 'Alice'} is not valid JSON. It must be {"name": "Alice"}.
  • Trailing commas: {"a": 1, "b": 2,} will fail. Remove the comma after the last value.
  • Unquoted keys: {name: "Alice"} is valid JavaScript but not valid JSON.
  • Comments: // this is a note or /* block comment */ will cause a parse error. JSON has no comment syntax.
  • Undefined and NaN: these are JavaScript values that have no JSON representation. Use null instead of undefined. NaN and Infinity must be represented as strings or null.
  • Duplicate keys: RFC 8259 says names should be unique, and parsers disagree about duplicates. JSON.parse keeps the last value, so the formatted output silently drops the earlier ones. If {"a": 1, "a": 2} comes out as {"a": 2}, your input had a duplicate key.
  • Hex numbers: 0xFF is valid JavaScript but not valid JSON. Use 255.
  • Single-value documents: a bare string like "hello" or number like 42 is valid JSON according to RFC 8259, though some older parsers expect a top-level object or array.

The output updates as you type, so you can fix the error in place and watch the formatted result appear.

When to Use a JSON Formatter

API debugging is the most common use case. You send a request with cURL, Postman, or fetch(), and the response comes back as a single line of minified JSON. Pasting it into the formatter gives you a readable view instantly. You can scan the structure, verify the response shape matches your TypeScript interface, and check for unexpected null values or missing fields.

For example, if you are debugging a failing API integration and the response body is a 4KB minified string, you are not going to find the problem by reading it as a single line. Format it, and you can immediately see that the address field is returning an empty object instead of the expected street/city/zip structure. Or you discover that the API wraps the data in an extra layer: {"data":{"result":{...}}} when you expected {"result":{...}}.

Configuration file editing is another major use case. Files like tsconfig.json, package.json, .eslintrc.json, appsettings.json, and firebase.json need to be valid JSON. A single misplaced comma or missing quote can break your entire build pipeline. Paste the file contents into the validator to check syntax before saving. This catches errors that your text editor's JSON extension might miss, especially in large config files.

Database exports and log analysis often produce large JSON blobs. When you export a MongoDB document, an Elasticsearch response, or a DynamoDB item, the output can be deeply nested with arrays of objects containing arrays of objects. Formatting helps you navigate these structures. If you need to inspect a deeply nested field, formatted output with proper indentation lets you trace the hierarchy visually.

Payload construction is when you build JSON by hand for testing. You might write a request body in a text editor to paste into Postman, cURL, or a fetch() call. The formatter validates your hand-written JSON before you send it, catching typos early. This is faster than sending the request, getting a 400 Bad Request error, and then figuring out which character is wrong.

Webhook debugging requires JSON formatting frequently. Services like Stripe, GitHub, Twilio, and Shopify send webhook payloads as JSON. When you set up a webhook endpoint and inspect incoming requests, the payloads are often large and minified. Formatting them reveals the event structure and the data available for processing.

Working with Large JSON Files

JSON files from database exports, analytics platforms, or API batch responses can reach tens of megabytes. The tool parses and highlights everything in memory with the browser's JavaScript engine, so very large inputs take longer to render and can slow the tab.

If you are working with extremely large JSON files regularly, consider using command-line tools like jq alongside the browser formatter. Use jq to filter and extract the subset you need, then paste that subset into the visual formatter for inspection. For example: cat large-export.json | jq '.results[0:10]' gives you the first 10 results, which you can then format visually. Other useful jq commands: jq 'keys' shows top-level keys, jq '.[] | length' counts elements, and jq '.users[] | select(.active == true)' filters arrays.

For files that contain arrays with thousands of identical objects (like a CSV-to-JSON conversion), formatting the entire file produces very long output. In these cases, format a single representative object to understand the structure, then use jq or scripting to process the full dataset.

Streaming JSON parsers (like JSONStream in Node.js or ijson in Python) handle files that do not fit in memory. They read the file incrementally and emit events for each token. The browser formatter is not designed for streaming, but it works well for the inspection-and-debugging workflow where you need to look at a specific portion of data.

JSON vs. Similar Formats

JSON is often confused with JavaScript object literals. The key difference: JSON requires double-quoted keys and string values, no trailing commas, no comments, and no functions. A JavaScript object like { name: 'Alice', age: 30, } is valid JS but invalid JSON. If you copy an object from a .js or .ts file, it will not validate as JSON.

JSON5 is a superset that allows single quotes, trailing commas, comments, unquoted keys, hexadecimal numbers, leading/trailing decimal points, and multi-line strings. JSONC (JSON with Comments) is used by VS Code configuration files like settings.json and tasks.json. It allows // and /* */ comments but not other JSON5 features. YAML is a superset of JSON that uses indentation instead of braces and supports comments, anchors, and multi-line strings. TOML uses a different syntax entirely with [sections] and key = value pairs.

This formatter handles strict JSON (RFC 8259). If you paste JSON5 or JSONC, it will report errors on the non-standard syntax. To convert JSON5 or JSONC to JSON, remove the non-standard features (strip comments, replace single quotes, remove trailing commas) and then format.

Common Mistakes and How to Avoid Them

Mistake 1: Pasting a JavaScript object instead of JSON. If you copy an object from your source code, it likely has unquoted keys or single-quoted strings. Convert it to JSON first using JSON.stringify() in your browser console: open DevTools, paste your object, wrap it in JSON.stringify(yourObject, null, 2), and copy the output.

Mistake 2: Including a BOM (Byte Order Mark) at the start of the string. Some text editors add an invisible BOM character (U+FEFF) when saving files. This causes a parse error at position 0. If you see an error at the very beginning of valid-looking JSON, try deleting and retyping the first character. Notepad on Windows and some older editors are common culprits.

Mistake 3: Escaped strings within strings. When JSON is embedded inside another string (like a database column, a log line, or a Redis value), the quotes are often escaped: {\"name\":\"Alice\"}. You need to unescape the string first before formatting. Remove the outer quotes and backslashes to get the raw JSON. Some tools call this double-serialized JSON.

Mistake 4: Concatenated JSON objects. Some log systems output one JSON object per line (NDJSON or JSON Lines format) without wrapping them in an array. If you paste multiple objects without an enclosing array and commas, the parser will fail after the first object. Either wrap them in brackets with commas [{first}, {second}] or process them line by line.

Mistake 5: Numeric precision issues. JSON numbers are parsed as IEEE 754 doubles. Integer values larger than 2^53 - 1 (9007199254740991) will lose precision. If your JSON contains large IDs like {"id": 9007199254740999}, the parsed value may differ from the original. This comes from JavaScript's number type, and it affects this formatter too. Because the output is re-serialized from the parsed value, a large ID appears rounded in the formatted result. Use string-typed IDs for values beyond the safe integer range. Twitter, Snowflake, and many distributed systems use 64-bit IDs that exceed this limit.

Mistake 6: Confusing empty values. {"name": ""} (empty string), {"name": null}, and {} (missing key entirely) are three different things. An empty string is a valid value, null indicates an explicit absence of value, and a missing key means the field was not included. The formatter shows these differences clearly.

Advanced Tips

Use the formatter as a diff preparation tool. Before comparing two JSON responses, format both with consistent indentation (same number of spaces). Then use a text diff tool to find the actual differences. Comparing minified JSON strings produces useless diffs because every character is on one line. Formatted JSON gives you line-by-line comparisons.

When working with nested JSON strings (a JSON string containing another JSON string as a value), format the outer JSON first, then copy the inner string value and format it separately. This happens often with JWT payloads, webhook bodies stored in databases, message queue payloads, and API gateway logs.

If you need to extract a specific path from formatted JSON, use the visual structure to identify the path, then use jq or JavaScript to extract it programmatically. For example, if you see that the email is at response.data.users[0].contact.email, you can write jq '.data.users[0].contact.email' or access it in code.

For API development, keep the formatter open in a pinned browser tab. Every time you test an endpoint, paste the response for a quick visual check.

The minify function is useful before storing JSON in environment variables, database fields, or URL parameters where whitespace adds overhead. A formatted config file with 200 lines might minify to a single line of 2KB, which fits cleanly in a .env value or a Kubernetes ConfigMap entry.

Validation before deployment catches errors that slip through code review. If your application reads a JSON config file at startup, validate that file with this tool as part of your pre-deployment checklist. A missing comma in a production config can take down a service, and these errors are easy to miss in code review when the diff is large.

JSON path notation helps when communicating about specific fields in a JSON document. Instead of saying the third user's second role, say users[2].roles[1]. The formatted view makes it easy to count indices and identify paths. Many logging systems and query languages (JSONPath, jq, JMESPath) use this dot-bracket notation.

Keyboard Workflow

Press Ctrl+A in the input, then Ctrl+V to paste new JSON over the old one. The output updates immediately. Use the copy button to copy the formatted result, or Minify & Copy for the compact version.

JSON Schema Validation

Beyond syntax validation, JSON Schema lets you validate the structure and types of your JSON data. A schema defines what keys are required, what types values should have, minimum/maximum values, string patterns, and more. While this tool validates JSON syntax, you can use the formatted output to visually verify that your data matches a schema. Check that required fields are present, arrays contain the expected types, and nested objects have the right shape.

Privacy and Security

The formatter processes everything client-side using your browser's JavaScript engine. No HTTP requests are made with your data. This matters when you are formatting JSON that contains API keys, authentication tokens, personal user data, financial records, or proprietary business logic. Unlike online formatters that send your data to a server for processing, this tool keeps everything local. You can verify this by opening your browser's Network tab and watching for outgoing requests while formatting. Check your own security policy before you paste production secrets into any web page.

JSON in Modern Development Workflows

Package.json is the most edited JSON file in the JavaScript ecosystem. Every npm and yarn project starts with one. Common validation issues include missing commas after adding new dependencies, mismatched quotes from copy-pasting, and accidental trailing commas from editors that auto-insert them. Paste your package.json here after manual edits to catch syntax errors before you run npm install.

Terraform state files (terraform.tfstate) are JSON files that can grow to hundreds of megabytes for large infrastructure deployments. These files contain sensitive information (resource IDs, IP addresses, sometimes secrets) and should never be pasted into server-side formatters. Use this client-side tool to inspect state file fragments when debugging Terraform drift or import issues.

Elasticsearch queries use JSON as the query language. Complex aggregations and nested bool queries can span hundreds of lines. Formatting the query before sending it to Elasticsearch helps catch structural errors. A missing closing bracket in a nested must/should/filter clause can produce unexpected results without throwing an error.

GraphQL responses are JSON. When debugging GraphQL queries, the response structure mirrors your query structure. Formatting the response helps you verify that nested fields resolved correctly and that null values appear where expected.

Docker Compose, while YAML-based, can be converted to JSON for processing. Docker inspect outputs JSON. Kubernetes kubectl get -o json returns JSON. Container orchestration debugging frequently involves formatting JSON output from these tools to understand resource configurations, pod status, and service endpoints.

Frequently asked questions

Is my data being saved?

No, your data stays only in your browser. No data is shared with us.

How can I find the error?

Invalid JSON shows the parser message from your browser. Current Chrome and Firefox include the line and column of the first character that broke the parse.

Does the formatter change my data?

It shows the parsed value re-serialized. Duplicate keys keep only the last value, and integers above 9007199254740991 appear rounded, so check those cases against your source.

Related guides

Related WebRecast sections