{ } JSON Editor and Validator
By Shihab Mia ยท Updated 2026-08-03
Edit the JSON above. Validation and stats update as you type.
This JSON editor and validator checks your JSON the moment you type it: a green "Valid JSON" badge appears when the syntax parses, and a red error with the exact parser message appears when it does not. Alongside the editor you get live stats, the top-level key count, the nesting depth, and the byte size, plus one-click Format (pretty-print with 2-space indent) and Minify buttons. Everything runs in your browser, so the JSON you paste never leaves the page.
What is the JSON Editor and Validator?
JSON (JavaScript Object Notation) is the text format that web APIs, config files, and JavaScript apps use to exchange structured data. It is built from just a few pieces: objects wrapped in curly braces with "key": value pairs, arrays in square brackets, strings in double quotes, numbers, the literals true, false and null, and nothing else. The rules are strict on purpose, which is exactly why a tiny mistake, a trailing comma, a single quote, or a missing bracket, breaks the whole document. A validator exists to point at that mistake instead of leaving you to hunt for it.
When you type or paste into the editor above, the tool runs JSON.parse on your text on every keystroke. If parsing succeeds, the value is valid JSON and the badge turns green. If it throws, the badge turns red and shows the browser's own SyntaxError message, which usually names the position where parsing failed. This is the same engine your code will use at runtime, so if it validates here it will parse in your app.
The stats line turns your JSON into three quick numbers. Top-level keys counts the entries at the root: the number of keys if the root is an object, or the number of items if it is an array. Nesting depth is measured recursively, a flat object of scalars is depth 1, an object that contains an array of objects is depth 3, and so on. Byte size is the actual UTF-8 size measured with new Blob([text]).size, which is what matters for payloads and storage, and it can differ from the character count when your JSON contains accented letters, emoji, or other multi-byte characters.
Format and Minify are the two everyday actions. Format runs JSON.parse then JSON.stringify with a 2-space indent, giving you readable, consistently indented output that is easy to diff and review. Minify runs JSON.stringify with no whitespace at all, collapsing the document to a single compact line for API bodies, query values, or anywhere size counts. Both only run on valid JSON, so they double as a validation step.
JSON shows up almost everywhere in modern software: REST and GraphQL API responses, configuration files such as package.json and tsconfig.json, NoSQL document stores like MongoDB, browser localStorage, and log lines emitted by servers. Because so much tooling assumes the JSON it reads is already correct, one broken character can crash a build, fail a deploy, or return a 500 error to a user. Validating the text before you commit it, send it, or paste it into another system is a small habit that avoids a disproportionately large amount of debugging later.
JSON is deliberately simpler than the formats it replaced or competes with. Unlike XML, it has no closing tags, no attributes versus elements distinction, and it maps directly onto arrays and objects in most programming languages, which is why JSON.parse gives you a usable value with no extra library. Unlike YAML, JSON has no significant whitespace and no ambiguous type coercion, which makes it stricter but also far less error-prone to generate by hand or by machine. This validator checks only syntax; if you also need to enforce that specific fields exist or have specific types, that is the job of a separate JSON Schema, which describes structure on top of syntax that is already valid.
When to use it
- Pasting an API response and confirming it is valid JSON before wiring it into your code.
- Cleaning up a minified or messy config file into readable, 2-space-indented JSON.
- Minifying a JSON payload to shrink an API request body or a stored config value.
- Finding the exact character where a hand-edited JSON file breaks, using the live parser message.
- Checking how deeply nested a document is, or how many top-level keys it holds, before working with it.
- Measuring the real byte size of a JSON payload to stay under an API or storage limit.
How to use the JSON Editor and Validator
- Type or paste your JSON into the editor. A sample object is loaded so you can see a valid result right away.
- Watch the badge: green means valid, red shows the exact parser error and where it failed.
- Read the stats row for top-level key count, nesting depth, byte size, and character count.
- Press Format for readable 2-space indentation, or Minify to collapse it to one compact line.
- Press Copy to put the current editor text on your clipboard, or Clear to start over.
Formula & method
Worked examples
You paste an API response and want to confirm it is valid, then read it comfortably.
- Paste: {"user":{"id":7,"tags":["a","b"]},"ok":true}
- The badge turns green and reads Valid JSON.
- Stats show 2 top-level keys (user and ok) and a nesting depth of 3 (root object to user object to tags array).
- Press Format to expand it into a readable, 2-space indented block.
Result: Confirmed valid, 2 top-level keys, depth 3, now pretty-printed and easy to scan.
A hand-edited config will not load and you need to find the broken character.
- Paste: {"port":8080,"hosts":["a","b",]}
- The badge turns red and shows the parser message, which flags the token after the last comma.
- The trailing comma before the closing bracket is the problem: JSON does not allow it.
- Delete that comma so the array reads ["a","b"].
Result: The badge flips back to green Valid JSON and Format now works on the fixed text.
You have a readable JSON object and need a compact version for an API request body.
- Paste: {"id": 42, "name": "Widget", "price": 19.99, "inStock": true}
- The badge turns green, Valid JSON, and stats show 4 top-level keys and a nesting depth of 1, since every value is a scalar.
- Press Minify to strip the whitespace, producing {"id":42,"name":"Widget","price":19.99,"inStock":true}.
- The byte size stat now reads 54 bytes for the minified line, all ASCII characters, so bytes equal character count here.
Result: Valid JSON, 4 top-level keys, depth 1, minified to a single 54-byte line ready to paste into an API body.
What the tool measures and how it is computed
| Stat | Meaning | How it is computed |
|---|---|---|
| Top-level keys | Entries at the root | Object: Object.keys(v).length; Array: v.length |
| Nesting depth | How deeply values nest | Recursive: 1 + max depth of children; scalar is 0 |
| Size (bytes) | UTF-8 payload size | new Blob([text]).size |
| Characters | Number of characters | text.length |
Common JSON syntax rules that trip people up
| Rule | Allowed | Not allowed |
|---|---|---|
| String quotes | "double quotes" | 'single quotes' |
| Trailing comma | {"a":1} | {"a":1,} |
| Keys | Always quoted strings | Unquoted keys like {a:1} |
| Comments | None permitted | // or /* */ comments |
| Root value | Object, array, string, number, true, false, null | Nothing, or an unquoted word |
The six JSON value types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Always double-quoted, supports unicode escapes like \u00e9 |
| Number | 42, -3.14, 1e6 | No leading zeros, no NaN or Infinity, no trailing decimal point |
| Boolean | true or false | Lowercase only, unquoted |
| Null | null | Lowercase only, represents an empty value |
| Object | {"key": "value"} | An unordered set of quoted-key and value pairs in curly braces |
| Array | [1, 2, 3] | An ordered list of values in square brackets, items can be any type |
Common mistakes to avoid
- Leaving a trailing comma. JSON does not allow a comma after the last item in an object or array. {"a":1,} and [1,2,] are both invalid even though many programming languages accept them. Remove the final comma.
- Using single quotes. JSON strings and keys must use double quotes. 'name' is invalid; it must be "name". This is the most common error when copying JavaScript object literals into a JSON file.
- Confusing JSON with a JavaScript object. A JS object can have unquoted keys, comments, trailing commas, and functions. JSON allows none of those. Valid JavaScript is not automatically valid JSON.
- Assuming byte size equals character count. Accented letters, emoji, and many non-Latin characters take more than one byte in UTF-8. A 10-character string can be 12 or more bytes, which is why the byte and character counts are shown separately.
- Using NaN, undefined, or Infinity as values. These are JavaScript concepts with no JSON equivalent. JSON.stringify silently turns NaN and Infinity into null, and it drops keys whose value is undefined entirely, which can corrupt data without ever throwing an error.
- Repeating the same key in one object. JSON syntax technically permits duplicate keys, but parsers keep only the last occurrence. {"a":1,"a":2} silently becomes {"a":2}, so a duplicate key is a bug even though it will not fail validation.
Glossary
- JSON
- JavaScript Object Notation: a strict, text-based format of objects, arrays, strings, numbers, and the literals true, false, and null.
- Validate
- To check that text is syntactically correct JSON. Here it means JSON.parse runs without throwing an error.
- Format (pretty-print)
- Rewriting JSON with consistent indentation and line breaks so it is easy to read; this tool uses a 2-space indent.
- Minify
- Removing all optional whitespace so the JSON is a single compact line, useful for smaller payloads.
- Nesting depth
- How many levels of objects and arrays are stacked inside each other, measured recursively from the root.
- Byte size
- The size of the text in bytes when encoded as UTF-8, which can be larger than the character count for multi-byte characters.
- JSON Schema
- A separate specification for describing the expected shape of JSON data, such as required fields and value types. This editor checks syntax, not a schema.
- Escape sequence
- A backslash-prefixed code inside a JSON string, such as \n for a newline or \u00e9 for a unicode character, used to represent characters that cannot appear literally.
Frequently asked questions
How do I validate JSON online?
Paste or type your JSON into the editor above. It is validated on every keystroke: a green badge means valid, and a red badge shows the exact parser error message. No button press is needed, validation is live.
What is the difference between Format and Minify?
Format pretty-prints your JSON with 2-space indentation and line breaks so it is easy to read and diff. Minify strips all whitespace to produce a single compact line, which is smaller for API bodies and storage. Both only run on valid JSON.
How is nesting depth calculated?
Depth is measured recursively. A plain object or array of scalars is depth 1. Each additional level of nested objects or arrays adds one, so an object containing an array of objects is depth 3. It is the length of the deepest path from the root.
Why does the byte size differ from the character count?
Byte size is the UTF-8 size measured with new Blob([text]).size, while characters is simply text.length. ASCII characters are one byte each, but accented letters, emoji, and many symbols take two to four bytes, so the two numbers can differ.
Is my JSON sent to a server?
No. All parsing, formatting, minifying, and stats run locally in your browser with vanilla JavaScript. Nothing you paste is uploaded, which makes the editor safe for private tokens, configs, or sensitive data.
Why does my JavaScript object show as invalid JSON?
JavaScript object literals allow things JSON forbids: single quotes, unquoted keys, trailing commas, and comments. Convert them to double-quoted keys and strings, remove trailing commas, and delete any comments to make the text valid JSON.
What are the six JSON data types?
JSON supports exactly six types: string, number, boolean, null, object, and array. There is no date, function, or undefined type, so values outside these six always need to be represented as one of them, usually a string.
Can this tool convert JSON to XML, CSV, or YAML?
No, this editor focuses on validating, formatting, and minifying JSON itself. For format conversion, export the validated JSON and use a dedicated converter tool.
What does an "Unexpected token" error mean?
It means the parser reached a character that cannot appear at that position, most often a trailing comma, a single quote, an unquoted key, or a missing comma between items. The error message names the token and its position so you can jump straight to the problem.
Is JSON5 or JSONC valid in this validator?
No. This editor validates strict JSON only, matching JSON.parse. JSON5 and JSONC allow extras like comments, trailing commas, and unquoted keys that strict JSON, and this validator, will reject.
Sources
- JSON.parse() , MDN Web Docs
- JSON.stringify() , MDN Web Docs
- The JSON Data Interchange Syntax (ECMA-404) , Ecma International