JSON Formatter & Validator

Format, validate, and minify JSON. Pretty-print with custom indentation, detect syntax errors, and minify for production. All processing is done in your browser.

JSON Input

Frequently Asked Questions

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Minified JSON omits all whitespace to reduce file size, but is unreadable. Formatting (pretty-printing) adds indentation and newlines to make the structure visually clear — essential when debugging API responses, config files, or data pipelines.
Common JSON syntax errors: trailing commas ([1, 2, 3,] is invalid — trailing commas are only valid in JavaScript, not JSON), unquoted keys ({key: "value"} — keys must be double-quoted strings), single-quoted strings ({'key': 'value'} — only double quotes are valid in JSON), comments (JSON has no comment syntax), and undefined values (JSON only supports null, not undefined).
JSON is a strict subset of JavaScript object syntax with additional rules: all string keys must be double-quoted, values can only be strings, numbers, booleans, null, arrays, or objects (no functions, Date, undefined, or BigInt), and there are no comments or trailing commas. JavaScript object literals are more permissive. JSON is language-independent and designed for data exchange, while object literals are JavaScript syntax.
2-space indentation is compact and common in JavaScript, Node.js, and web projects (Prettier default is 2 spaces). 4-space indentation offers greater visual depth, common in Python and C# codebases. Tab indentation lets each developer use their own tab width preference. For JSON config files and APIs, 2 spaces is the most common choice; choose based on your team's style guide.
No — standard JSON (RFC 8259) does not support comments. If you need comments in config files, use JSONC (JSON with Comments, used by VS Code), JSON5, YAML, or TOML. For configuration files, many tools accept JSONC files with a .jsonc extension. Never add JavaScript-style // or /* */ comments to JSON that will be parsed by JSON.parse() — it will throw a SyntaxError.
JSON numbers are IEEE 754 doubles (64-bit floating point). Integers beyond ±2⁵³ (9,007,199,254,740,992) lose precision when parsed by JavaScript. For large integers (Twitter IDs, database bigints), the common approach is to serialize them as strings instead of numbers and parse them accordingly. Some parsers support BigInt. Always verify that your JSON consumer can handle the precision required for your numeric values.
JSON only supports null — there is no undefined in JSON. In JavaScript, when you JSON.stringify an object with undefined values, those keys are omitted from the output. Functions and Symbols are also silently omitted. This can cause subtle bugs when you expect a key to be present with a null value but it disappears from the serialized JSON. Explicitly set fields to null instead of leaving them undefined when the field must be present in the JSON.
Minifying JSON removes all insignificant whitespace (spaces, tabs, newlines) while preserving the data. This reduces file size, typically by 20–40% for API responses. In PHP: json_encode($data) (no options produces minified JSON). In JavaScript: JSON.stringify(data). In Node.js CLI: node -e "process.stdout.write(JSON.stringify(require('./data.json')))". This tool's Minify button does the same transformation in your browser.
JSON is preferred over XML for REST APIs because: it is more concise (no opening and closing tags), easier to parse natively in JavaScript (JSON.parse() vs. DOM parsing), maps directly to data types (arrays, objects, primitives), and produces smaller payloads. XML offers advantages for document-centric data (XSLT transforms, schema validation with XSD, namespace support). For most web and mobile API use cases, JSON is the industry standard choice.
JSON strings must escape certain characters with a backslash: \" for double quote, \\ for backslash, \/ for forward slash (optional), \n for newline, \r for carriage return, \t for tab, \b for backspace, \f for form feed, and \uXXXX for any Unicode code point. Characters outside the Basic Multilingual Plane (like some emoji) require a surrogate pair: 😀 for 😀.

About This JSON Formatter & Validator

This free JSON formatter and validator formats, validates, and minifies JSON entirely in your browser using the native JSON.parse() and JSON.stringify() APIs. No data is sent to a server.

When to use this tool

  • Formatting a minified API response for readability
  • Validating JSON config or data files for syntax errors
  • Minifying JSON before embedding in source code
  • Debugging malformed JSON from logs or webhooks

Related Articles

In-depth guides and technical articles.

View all →
Why JSON Parses Differently in JavaScript, Python, and Go — Precision, Duplicates, and Parser Security
JSON's specification deliberately leaves number precision, duplicate key handling, and Unicode surrogate pairs as implementation-defined — which is why identical JSON produces different results in JavaScript (integers lose precision above 2^53), Python (arbitrary precision integers), and Go (float64 by default). Here's the parser differential security attack from duplicate keys, prototype pollution via JSON merge, and why NDJSON enables streaming gigabyte datasets with constant memory.
Why JSON Doesn't Allow Comments — and the JSON5/JSONC Variants That Do (and Why They Break Standard Parsers)
JSON5 and JSONC add comments and trailing commas to JSON — and if you've ever tried to add a // comment to a tsconfig.json and wondered why VS Code allows it but JSON.parse() doesn't, you've encountered the JSON variant ecosystem. Here's why JSON has no comments by design, the three overlapping "JSON with comments" specifications, why standard parsers reject JSONC content, and the preprocessing approaches for handling these variants in automation.
Structured JSON Logging: How to Debug Production API Errors and Search Logs at Scale
Structured JSON logs are queryable across millions of events in milliseconds; unstructured string logs require brittle grep. Here's why JSON logging matters, the OpenTelemetry log schema standard, structured logging libraries in Python/Node/Go, and how formatting API error responses reveals everything needed to debug a production incident.
Why 9007199254740993 Becomes 9007199254740992: JSON Numbers and JavaScript's Precision Limit
A JSON number like 9007199254740993 can become 9007199254740992 just by being parsed in JavaScript — not a bug in the parser, but a mismatch between JSON's unlimited-precision number specification and JavaScript's double-precision floating point, which can't represent integers above 2^53 exactly. Here's why this specifically affects large database IDs, the common "represent as string" workaround, and why this creates cross-language inconsistencies when backends and JavaScript frontends disagree about what "the same number" means.
JSON Schema Validation and API Contracts: OpenAPI, Contract Testing, and Validation Libraries
JSON Schema validates structure and constraints — and OpenAPI uses it as the contract format for API documentation, client SDK generation, and contract testing. Here's how JSON Schema works, key validation keywords, how OpenAPI extends it, and how Pact implements consumer-driven contract testing.