JSON Explained: A Beginner’s Guide to Syntax, Types and Errors
Updated November 2026
JSON (JavaScript Object Notation) is a plain-text format for structured data. It began as a subset of JavaScript’s object syntax, but today almost every programming language reads and writes it, and it is the default format for web APIs, many configuration files and countless data exports. The rules fit on a single page, yet one small mistake, such as an extra comma or the wrong kind of quote, makes a whole document unreadable to a program. This guide covers the rules, the data types, the errors you will meet most often and how to fix them.
What JSON looks like
A JSON document is a single value. Usually that value is an object in curly braces or an array in square brackets, which contains other values:
{"name": "Mina", "age": 31, "languages": ["Korean", "English"], "manager": null}
The rules are short:
- An object holds name–value pairs inside
{ }. Each name (the key) is a string in double quotes, followed by a colon and a value. - An array holds an ordered list of values inside
[ ]. One array can mix values of different types. - Items are separated by commas, with no comma after the last item.
- Strings use double quotes only. Inside a string, a double quote is written
\", a backslash\\and a line break\n. - Spaces, tabs and line breaks between items are ignored, so the same data can sit on one line or be spread over many.
- There are no comments, variables or functions. JSON is data only.
The format is defined by two matching standards, ECMA-404 and RFC 8259. RFC 8259 also requires JSON exchanged between systems to be encoded as UTF-8, so text such as 한국어, 日本語 or emoji can be included directly.
The six data types
| Type | Examples | Rules |
|---|---|---|
| String | "Seoul", "caf\u00e9" | Double quotes only; \u escapes allowed |
| Number | 42, -3.5, 1.2e6 | No leading zeros, no leading +, no hex, no NaN or Infinity |
| Boolean | true, false | Lowercase only |
| Null | null | Means “no value”; lowercase only |
| Object | {"id": 7} | Keys are strings and should be unique |
| Array | [1, "two", false] | Ordered; types can be mixed |
Notice what is missing. There is no date type: dates are usually stored as ISO 8601 strings such as "2026-11-05T14:30:00Z" or as Unix timestamps, both explained in the Unix time guide. There is no separate integer type either, and many parsers, including JavaScript’s, store every number as a 64-bit floating-point value. Integers above 9,007,199,254,740,991 can silently change: JavaScript reads {"id": 9007199254740993} as 9007199254740992. That is why large IDs are often sent as strings.
JavaScript’s JSON.stringify also quietly changes values JSON cannot represent: object properties set to undefined are dropped, and NaN and Infinity become null.
Common errors and how to fix them
JSON parsers are strict: one mistake and the whole document is rejected. The error message gives a position, but it often points just after the real problem. A trailing comma, for example, is reported at the closing bracket that follows it. These are the errors you will meet most often:
| Problem | Invalid | Fixed |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'name': 'Mina'} | {"name": "Mina"} |
| Unquoted key | {name: "Mina"} | {"name": "Mina"} |
| Comment | {"port": 8080 // dev} | {"port": 8080} |
| Missing comma | [1, 2 3] | [1, 2, 3] |
| Python-style values | {"ok": True, "x": None} | {"ok": true, "x": null} |
| Leading zero | {"code": 007} | {"code": "007"} |
| Unescaped backslash | {"path": "C:\Users\mina"} | {"path": "C:\\Users\\mina"} |
| Line break typed inside a string | Enter pressed between the quotes | "line 1\nline 2" |
| JavaScript-only value | {"x": undefined} | {"x": null} |
Some of these have a clear origin. Single quotes, True and None usually mean someone printed a Python dictionary instead of serialising it with json.dumps: the output looks like JSON but is not. Comments and trailing commas often come from configuration files written in JSONC or JSON5, relaxed variants accepted by some tools, such as VS Code’s settings.json and TypeScript’s tsconfig.json. Standard parsers reject both. If you need a note inside pure JSON, add an ordinary field such as "_comment".
The fastest way to find a mistake is to paste the document into the JSON Formatter. It checks the JSON as you type, shows the line and column of the first error and jumps to it when you click Format.
Pretty-print vs minify
Because whitespace between items is ignored, the same data can be written in two styles. Pretty-printed JSON puts each value on its own line and indents nested values, so the structure is visible at a glance. Minified JSON removes every unnecessary space and line break. The record {"id": 1042, "name": "Mina Park", "roles": ["editor", "admin"]} takes 57 bytes minified and 83 bytes pretty-printed with two-space indentation, yet both versions hold exactly the same data.
| Pretty-printed | Minified | |
|---|---|---|
| Best for | Reading, debugging, config files, code review | API responses, storage, embedding in other text |
| Size | Larger; indentation adds up in deep nesting | As small as the data allows |
| Version control | Changes show up line by line | One long line, so any change rewrites it all |
Over the network the difference is smaller than it looks, because servers usually compress responses with gzip or Brotli, and repeated spaces compress very well. A practical habit is to store and send minified JSON and pretty-print it when a person needs to read it.
JSON vs CSV
CSV (comma-separated values) is the other everyday format for exchanging data, especially with spreadsheets. Here are the same two records in each format. As JSON: [{"name": "Mina", "city": "Busan", "score": 92}, {"name": "Leo", "city": "Lyon", "score": 87}]. As CSV, a header line name,city,score followed by one line per record: Mina,Busan,92 and Leo,Lyon,87.
| JSON | CSV | |
|---|---|---|
| Shape | Nested objects and arrays | A flat table of rows and columns |
| Types | Strings, numbers, booleans, null | Everything is text; the reader guesses |
| Field names | Repeated in every object | Once, in the header row |
| Size of table-like data | Larger | Smaller |
| Opens in | Code editors, browsers, APIs | Excel, Google Sheets, databases |
A simple rule: if the data fits naturally in a spreadsheet and people will open it in Excel, use CSV. If it has nested parts (a customer with several addresses), needs real types, or is travelling between programs, use JSON. Watch for CSV’s weak spots, too: values containing commas must be quoted, and spreadsheet apps may strip the leading zero from a postcode such as 02134. The CSV ⇄ JSON Converter handles quoting in both directions and writes nested values as JSON text inside a single cell.
Where you will meet JSON
- Web APIs. Most REST APIs send and receive JSON, labelled with the header
Content-Type: application/json. The Network tab of your browser’s developer tools shows these responses. - Configuration.
package.jsonin JavaScript projects,composer.jsonin PHP and the settings files of many apps. - Login tokens. A JSON Web Token carries small JSON objects encoded with Base64url. That is why tokens almost always begin with
eyJ: it is how{"followed by a letter looks once encoded. The JWT Decoder turns tokens back into readable JSON. - Logs and exports. JSON Lines files (
.jsonl) hold one JSON object per line, so huge files can be processed line by line. - Databases and browsers. PostgreSQL has
jsonandjsonbcolumn types, and web apps often keep settings in local storage as JSON strings.
Reading and writing JSON in code
| Language | Text → data | Data → text |
|---|---|---|
| JavaScript | JSON.parse(text) | JSON.stringify(data, null, 2) |
| Python | json.loads(text) | json.dumps(data, indent=2, ensure_ascii=False) |
| PHP | json_decode($text, true) | json_encode($data, JSON_PRETTY_PRINT) |
In Python, ensure_ascii=False keeps text such as “서울” readable instead of turning it into \uc11c\uc6b8. Python’s json module also reads and writes NaN and Infinity by default, which other parsers reject; pass allow_nan=False to json.dumps when the output is going to another system.
Related tools
- JSON Formatter – validate, pretty-print or minify JSON and find the line of an error.
- CSV ⇄ JSON Converter – turn spreadsheet data into JSON and back.
- JWT Decoder – read the JSON inside a JSON Web Token.