What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for exchanging structured data. It represents data as nested objects and arrays of values, is readable by humans, and can be parsed by every mainstream programming language — which is why nearly every web API sends and receives JSON.
This guide covers the syntax you need to write valid JSON, the mistakes that produce "Unexpected token" errors, how to format, validate and convert JSON in your browser, and when another format is a better choice.
JSON syntax: the six value types
A JSON document is a single value. That value is usually an object or an array, but the standard (RFC 8259) allows any of six types at the top level.
- Object — an unordered set of key/value pairs inside braces: {"id": 7, "name": "Layla"}. Keys must be strings in double quotes.
- Array — an ordered list of values inside brackets: ["admin", "editor"].
- String — text in double quotes, with backslash escapes for quotes, backslashes and control characters: "line one\nline two".
- Number — an integer or decimal, optionally with an exponent: 42, -3.5, 1.2e10. No leading zeros, no hex, no NaN or Infinity.
- Boolean — the literals true and false (lower-case).
- null — the literal null, meaning "no value".
{
"user": { "id": 7, "name": "Layla", "active": true },
"roles": ["admin", "editor"],
"lastLogin": null,
"balance": 1250.75
}The rules that cause most JSON errors
JSON looks like JavaScript but is much stricter. Almost every "Unexpected token" or "Unexpected end of JSON input" error comes from one of these rules.
- Keys and strings use double quotes only. 'single quotes' are invalid.
- No trailing commas: [1, 2, 3,] and {"a": 1,} are errors.
- No comments. Neither // nor /* */ is allowed anywhere in the document.
- Keys must be quoted: {name: "Layla"} is JavaScript, not JSON.
- Numbers cannot have leading zeros (007) or a trailing decimal point (5.).
- The document must contain exactly one top-level value — two objects side by side are not valid JSON (that is JSON Lines).
- Encoding is UTF-8. A byte-order mark at the start of the file will break many parsers.
How to format (pretty-print) JSON
APIs usually send JSON minified — every space and line break removed — because it is smaller. Formatting adds the indentation back so the structure is visible. Paste the text into a formatter, choose 2-space, 4-space or tab indentation, and copy the result; a good formatter also reports the exact line and column of any syntax error and can sort object keys so that two documents can be compared.
In code, JSON.stringify(value, null, 2) in JavaScript, json.dumps(value, indent=2) in Python and jq . file.json on the command line do the same job.
How to validate JSON
Validation has two levels. Syntax validation checks that the text is well-formed JSON — that every bracket is closed and every rule above is respected. Schema validation goes further and checks the structure against a JSON Schema: which keys are required, what type each value must be, allowed ranges and patterns.
Use syntax validation while debugging a payload that will not parse, and schema validation when you own an API contract and want to catch responses that drift away from it.
Try it: JSON Validator Try it: JSON Schema Validator Try it: JSON Schema Generator
JSON vs XML vs YAML
JSON replaced XML as the default web format because it is smaller, maps directly onto the data structures of most languages and needs no schema to be useful. XML remains common in enterprise and SOAP systems and supports attributes, namespaces and comments that JSON lacks.
YAML is a superset of JSON designed for humans to write — configuration files, CI pipelines, Kubernetes manifests. It allows comments and omits most punctuation, but its whitespace sensitivity makes it a poor choice for machine-to-machine exchange. The rule of thumb: JSON for APIs and storage, YAML for configuration, XML when a system requires it.
Try it: JSON to YAML Try it: JSON to XML Try it: XML to JSON Try it: YAML Formatter Try it: XML Formatter Try it: XML Validator
Converting JSON to CSV, SQL and other formats
Flat JSON arrays of objects convert cleanly to CSV: each object becomes a row and each key a column. Nested objects need to be flattened first (user.address.city becomes a column named user.address.city). The same shape maps onto SQL INSERT statements, which is the quickest way to load API data into a database for analysis.
Try it: JSON to CSV Try it: CSV to JSON Try it: JSON to SQL Try it: JSON Flatten / Unflatten
Working with large JSON documents
A tree viewer is the practical way to read a document with thousands of lines: collapse what you do not need, expand one branch at a time and copy the JSONPath of any value. To find or extract specific values programmatically, JSONPath expressions such as $.users[?(@.active)].email select exactly the nodes you want.
Try it: JSON Tree Viewer Try it: JSON Path Tester Try it: JSON Diff
Frequently asked questions
Is JSON a programming language?
No. JSON is a data format — a way of writing structured values as text. It has no variables, functions or logic. It is derived from JavaScript object syntax but is independent of any language.
What file extension does JSON use?
The .json extension, and the MIME type application/json. JSON Lines files (one JSON value per line) use .jsonl or .ndjson.
Can JSON contain comments?
Standard JSON cannot. Some tools accept a relaxed dialect (JSONC, JSON5) that allows comments and trailing commas, but APIs and most parsers reject them.
Why does my JSON fail with "Unexpected token"?
The parser met a character it did not expect — most often a trailing comma, a single-quoted string, an unquoted key or a comment. A validator shows the exact line and column.
Is JSON safe to paste into an online tool?
Only if the tool processes it locally. The Mutqan JSON tools run entirely in your browser and never upload what you paste, so API responses containing tokens or personal data stay on your machine.
What is the difference between JSON and a JavaScript object?
A JavaScript object lives in memory and can hold functions, undefined, Dates and references; JSON is a text serialization with only six value types. JSON.parse turns text into an object; JSON.stringify does the reverse.
Tools mentioned in this guide
Format, beautify and validate JSON instantly in your browser with custom indentation.
Validate JSON syntax and get precise error locations with helpful fix suggestions.
Explore JSON as a collapsible tree with paths, types and value counts.
Minify JSON by removing whitespace to reduce payload size.
Compare two JSON documents semantically and highlight added, removed and changed values.
Convert an array of JSON objects to CSV with flattened nested keys.
Convert JSON to clean, readable YAML.
Validate a JSON document against a JSON Schema (draft-07 / 2019-09 / 2020-12 core keywords).