JSON Formatter & Validator
JSON is everywhere โ API responses, config files, logs, data exports. Having a fast, reliable formatter that runs locally without sending your data anywhere is worth knowing about.
JSON Formatter
Prettify, validate, minify, and compare JSON โ all client-side.
What is JSON?
JSON stands for JavaScript Object Notation. It was originally derived from a subset of the JavaScript language, but it has long since become a language-independent data interchange format. The JSON specification is defined by ECMA-404 and RFC 8259, and virtually every programming language in use today can parse and produce it.
A JSON document can represent six types of values: strings (always double-quoted), numbers, booleans (the literals true and false), null, arrays (ordered lists enclosed in square brackets), and objects (unordered collections of key-value pairs enclosed in curly braces, where keys must be strings). These six building blocks can be nested arbitrarily, which makes JSON expressive enough to represent almost any data structure.
JSON's success comes from its simplicity. It is human-readable in a way that binary formats like Protocol Buffers or MessagePack are not, and it is less verbose than XML. A REST API that returns a user record might look like this:
{
"id": 42,
"name": "Alice Nguyen",
"email": "alice@example.com",
"roles": ["editor", "reviewer"],
"active": true,
"metadata": {
"createdAt": "2025-03-15T08:00:00Z",
"lastLogin": "2026-06-01T14:23:11Z"
}
}That same data minified โ with all whitespace stripped โ becomes a single line. Both are valid JSON. The parser does not care about whitespace. Humans care about whitespace, which is exactly why formatting tools exist.
Why a dedicated JSON formatter?
Most developers reach for JSON.stringify(obj, null, 2) in the browser console when they need a quick look at some data. That works for small objects, but it breaks down fast โ no syntax highlighting, no error messages with line numbers, no way to diff two responses to see what changed between API versions.
The sourcecodestack JSON Formatter handles the full workflow: paste raw JSON from an API response, get it formatted with highlighting in under a second, validate that it's actually valid (not just "looks like JSON"), minify it back for embedding in code, and diff it against another version.
What it handles
Prettifying vs. minifying โ when to use each
Prettifying and minifying are inverses of each other, and both are legitimate transformations of valid JSON. Understanding when to apply each one is useful.
Prettifying (pretty-printing)
Prettifying takes compact or inconsistently indented JSON and rewrites it with consistent indentation and line breaks so that each key-value pair and array element occupies its own line. The result is significantly longer in bytes but far easier to read. This is the format you want when:
- โขDebugging an API response and trying to understand the data structure
- โขReviewing a JSON config file in a pull request code review
- โขWriting documentation that includes example JSON payloads
- โขStoring JSON in files that will be committed to version control (pretty-printed diffs are far more readable in git)
// Minified input
{"user":{"id":1,"name":"Bob","active":true}}
// Prettified output (2-space indent)
{
"user": {
"id": 1,
"name": "Bob",
"active": true
}
}Minifying
Minifying strips every character of whitespace that is not inside a string value, producing the most compact valid JSON representation. For a typical API response, minification can reduce file size by 20โ40%, which matters in contexts like:
- โขEmbedding JSON in an HTML
<script type="application/json">tag, where extra whitespace increases page weight - โขStoring JSON in a database column with a character or byte limit
- โขGenerating a compact JSON string to include in a URL parameter or cookie value
- โขReducing the payload size of an API request when network bandwidth is a concern
Note that minification is a lossless transformation โ the semantic content of the JSON is identical before and after. A JSON parser reading the minified form will produce exactly the same data structure as one reading the prettified form.
Choosing your indent size
Two-space indentation is common in JavaScript and web projects (and is the default in JSON.stringify). Four-space indentation is traditional in Python (where json.dumps(obj, indent=4) is the convention) and in many Java and C# codebases. Tab indentation aligns with some style guides and makes it easy for each developer to customize display width in their editor. The tool remembers your preference between sessions so you don't need to set it again each time.
Validating JSON and the most common errors
JSON has a strict specification. Unlike HTML, which browsers parse with liberal error correction, a JSON parser is required to reject any document that does not conform exactly to the grammar. This strictness is intentional โ it makes JSON unambiguous and ensures that every compliant parser produces the same result for the same input. The downside is that small syntactic mistakes cause parse failures with sometimes cryptic error messages.
This tool validates by calling JSON.parse() and catching any exception. When parsing fails, the error includes a character position that gets translated to a human-readable line and column number. These are the most common errors to watch for:
Trailing commas
This is the single most frequent JSON error. JavaScript allows trailing commas in arrays and objects; JSON does not. If you generate JSON by hand or from a template, a trailing comma after the last element is an easy mistake to make.
// Invalid JSON โ trailing comma after "c"
{
"a": 1,
"b": 2,
"c": 3, โ this comma is invalid
}
// Valid JSON
{
"a": 1,
"b": 2,
"c": 3
}Single-quoted strings
JSON requires all strings โ both keys and values โ to be enclosed in double quotes. Single quotes are valid in JavaScript but not in JSON. This error commonly appears when JSON is hand-written or copied from JavaScript source code.
// Invalid JSON โ single-quoted strings
{ 'name': 'Alice' }
// Valid JSON โ double quotes only
{ "name": "Alice" }Unquoted keys
In JavaScript object literals, keys do not need to be quoted if they are valid identifiers. In JSON, all keys must be quoted strings without exception.
// Invalid JSON โ unquoted key
{ name: "Alice" }
// Valid JSON
{ "name": "Alice" }Comments
JSON does not support comments. Neither // single-line nor /* block */ comments are valid. This surprises developers coming from configuration file formats like YAML (which allows comments) or JSON5 (a superset of JSON that does). If you need a JSON-like config format with comments, consider JSONC (JSON with Comments, used by VS Code's settings) or YAML instead.
NaN, Infinity, and undefined
JavaScript has the special numeric values NaN and Infinity, and the type undefined. None of these are valid JSON values. If you serialize a JavaScript object that contains NaN or Infinity, JSON.stringify will silently convert them to null, which is valid. If those values appear literally in a JSON string (for example, because a buggy serializer wrote them out), the validator will reject the document.
Feature deep dive
Format & Prettify
Paste any valid JSON and click Format (or press Ctrl+Enter). The output uses your chosen indent size โ 2 spaces for tight readability, 4 spaces if you prefer more visual separation. Keys, string values, numbers, booleans, and null all get different colors so you can scan structure at a glance.
The tricky part with large JSON blobs (think 5,000+ line API responses) is performance. The formatter avoids re-rendering on every keystroke โ it only formats when you explicitly trigger it, which keeps the UI responsive.
Validate & Error Detection
Validation uses JSON.parse() under the hood, which gives you the browser's native JSON parser. When it fails, the error message includes the position in the string โ the formatter converts that to a human-readable line and column number so you can jump straight to the problem.
Common issues it catches: trailing commas (valid in JS, not in JSON), single-quoted strings, unquoted keys, comments, and NaN or Infinity values (not valid JSON).
JSON Diff View
Switch to the Diff tab and paste two JSON objects โ one in each panel. The tool does a deep structural comparison, showing added keys in green, removed keys in red, and changed values highlighted inline. It recurses into nested objects and arrays.
This is particularly useful when debugging why an API response changed between environments, or comparing a config file before and after a deployment.
Minify
Minification strips all whitespace and newlines, producing the most compact valid JSON representation. Useful when you need to embed JSON in a script tag, store it in a database field with character limits, or reduce payload size for an inline data attribute. The minified output shows the character count reduction.
Practical workflows
Understanding the tool's features is useful; knowing how they fit into real development workflows is even more useful. Here are several common scenarios where a JSON formatter genuinely speeds things up.
Debugging API responses
When you receive a minified JSON response from an API โ from a network tab in browser DevTools, from a curl command, or from a log file โ pasting it into the formatter immediately makes the structure navigable. You can see which fields are present, which are nested, and what types the values are. This is faster than writing a quick script to parse and print it.
A typical debug flow: copy the response body from the browser network panel, paste it here, format it, then use the structure to identify the exact JSON path you need (for example, response.data.items[0].metadata.id) to use in your code.
Comparing staging vs. production responses
When a feature works in one environment but not another, the first step is often to check whether the API response is different. Paste the staging response into the left diff panel and the production response into the right panel. The diff view immediately highlights which keys have different values, which are missing, and which are new. This is far faster than reading two long JSON blobs side by side or writing a comparison script.
Fixing hand-written JSON config files
Configuration files like package.json, tsconfig.json, or custom application configs are often edited by hand and break silently. Pasting the file content into the validator immediately shows whether there is a syntax error and where it is. The error message points to the line and column, which is much more useful than a generic "failed to parse config" error from a build tool.
Preparing JSON for embedding in code or documentation
When writing API documentation or code comments that include JSON examples, you often want the JSON formatted consistently with a specific indent size. Paste any JSON here, choose your indent preference, format it, and copy the result. When embedding JSON in a script tag or as a constant in code, minify it first to avoid unnecessary whitespace in the source.
How to use it
Paste your JSON
Paste raw JSON into the input panel. It can be minified, partially formatted, or even a single-line string with escape sequences.
Choose your indent size
Pick 2 spaces, 4 spaces, or tab from the settings. The preference is saved so you don't have to re-set it every visit.
Click Format or press Ctrl+Enter
The formatted output appears instantly in the right panel with full syntax highlighting.
Validate or Minify
Use the Validate button to check for syntax errors, or Minify to get the compact form. Both work on the current input.
Copy the result
Click Copy to grab the formatted or minified JSON to your clipboard. For diffs, switch to the Diff tab and paste your comparison JSON.
Who needs this
API developers
Inspect and validate response payloads during development, or compare responses between staging and production.
DevOps engineers
Format and validate JSON config files for Kubernetes manifests, Terraform outputs, or CI pipeline configs before committing.
QA testers
Quickly check if an API response matches expected structure by diffing against a known-good snapshot.
Frontend devs
Debug API data structures, minify JSON for inline use in HTML, or format localStorage/sessionStorage content for inspection.
JSON and data privacy
API responses, log data, and config files often contain sensitive information: user IDs, authentication tokens, internal service URLs, or personally identifiable information. Pasting this data into an online tool that processes it server-side means sending it to a third party, which may violate your organization's data handling policies or applicable regulations.
This formatter processes all JSON entirely in your browser. The JavaScript runs locally, and the page makes no network requests once loaded. Your JSON does not leave your machine. This makes it safe to use with data that would otherwise require a locally installed tool โ for development and debugging purposes, it behaves exactly like running python -m json.tool or jq '.' in a terminal, just with a more convenient interface.
If you are working with highly classified data or under strict security requirements, the conservative choice is still to use local command-line tools. But for the typical development and debugging workflow, a browser-based formatter that never phones home is a reasonable option.
Tips worth knowing
- โIf you're pasting a JSON string that contains escaped quotes, the formatter will unescape them automatically so the structure is readable.
- โFor very large files (10MB+), open your browser console and use JSON.stringify(JSON.parse(text), null, 2) instead โ the formatter is optimized for interactive use, not bulk processing.
- โThe diff view normalizes key order before comparing, so objects with the same keys in different order are treated as equal.
- โYou can paste a URL-encoded JSON string (e.g., from a query parameter) and the formatter will decode it first.
- โIf you need to extract a specific value from deeply nested JSON without writing code, format the JSON first and visually trace the path โ then you have the exact key path to use in your code.
- โWhen copying minified JSON to embed in a JavaScript string literal, remember to escape any double quotes or backslashes in the JSON if you're wrapping it in double quotes.
Frequently Asked Questions
Does the JSON Formatter upload my data?
No. All JSON parsing and formatting happens entirely in your browser using native JavaScript. Nothing is sent to any server.
Can I compare two JSON objects to find differences?
Yes. Switch to the Diff tab, paste your two JSON objects into the left and right panels, and the tool highlights added, removed, and changed keys with color-coded annotations.
What indent sizes are supported?
You can choose 2 spaces, 4 spaces, or a tab character. The setting applies immediately and persists across sessions using localStorage.
How does the JSON validator work?
The formatter uses JSON.parse() to validate syntax. If parsing fails, the exact error message and line number are displayed inline so you can find the problem immediately.
Why does my JSON fail validation even though it looks correct?
The most common causes are trailing commas after the last item in an object or array, single-quoted strings, unquoted keys, comments (not supported in JSON), and special values like NaN or Infinity which are valid JavaScript but not valid JSON.
What is the difference between prettifying and minifying JSON?
Prettifying adds indentation and newlines to make the JSON human-readable. Minifying removes all whitespace to produce the most compact valid form. Both are lossless โ a JSON parser reading either produces the exact same data structure.
Related Articles & Guides
What Is JSON? Complete Guide to JSON Formatting
JSON โ JavaScript Object Notation โ is the lingua franca of modern web development. Open any REST APIโฆ
Read guide โArticleJSON Formatter & Validator: Prettify, Minify, and Diff JSON Online
Format, validate, minify, and compare JSON objects side by side โ all in your browser.
Read guide โBlogDate & Time Calculations: Complete Developer Guide
Dates and times are deceptively simple. You look at a calendar, count the boxes between two dates, and callโฆ
Read guide โ