If you've wondered how a weather app gets the temperature from a server, or how a website remembers your settings, the answer is often JSON. This guide explains what it is, how to read it and where you'll run into it, without assuming you write code.
What is JSON?
JSON (JavaScript Object Notation) is a text format for storing and sending structured data. It writes information as names and values, such as "city": "London", grouped with curly braces and square brackets, so people can read it and programs can parse it. Two matching standards define it, RFC 8259 from the IETF and ECMA-404, both published in December 2017, and its official media type is application/json. Web APIs and configuration files use it constantly.
The "digital postcard" analogy
When I first started coding, JSON confused me. Then I realized it's just like a postcard. The "To" and "From" fields are the keys, and the names written next to them are the values. It's an organized way to send a message that any post office (or server) can understand. Written as JSON, the postcard looks like this:
{
"to": "Grace Hopper",
"from": "Ada Lovelace",
"message": "Wish you were here"
}
I use JSON daily, for everything from site configuration to pulling data from tools, and I think its simplicity is why it beat out XML for so much of the web.
How to read a JSON object
{
"name": "Ada Lovelace",
"born": 1815,
"isProgrammer": true,
"languages": ["English", "French"],
"address": {
"city": "London",
"country": "UK"
},
"website": null
}
Read it from the outside in. The curly braces hold one object. Each line inside is a name/value pair: the name in double quotes, a colon, then the value, with a comma between pairs. "languages" holds a list in square brackets, "address" holds another object inside the first one, and null means "deliberately empty". The example is 187 bytes as written; with the spaces and line breaks removed it's 146 bytes, and a program reads both versions the same way.
RFC 8259 says JSON can represent four primitive types and two structured ones. That's the whole list:
| Type | Example | What to know |
|---|---|---|
| String | "Ada Lovelace" | Text, always in double quotes |
| Number | 1815, -4.5, 1e3 | No quotes, no leading zeros, no NaN |
| Boolean | true, false | Lowercase only |
| Null | null | An intentional "no value" |
| Object | {"city": "London"} | Named values in curly braces; the spec calls it unordered |
| Array | ["English", "French"] | An ordered list in square brackets; items can be any type |
JSON format rules that trip people up
- Double quotes only, around every name and every string.
- No comma after the last item in an object or list.
- No comments anywhere.
true,falseandnullmust be lowercase.- There is no date type. Dates are written as strings such as
"2026-01-01"or as numbers.
Break any of these and the whole file fails to load. The exact error each one causes, and the fix, is in the 7 most common JSON formatting errors.
What is JSON used for?
JSON is used wherever two programs need to pass structured data as plain text. These are the places you are most likely to meet it:
- Web APIs. When an app asks a server for data, the reply is often a JSON object such as
{"city": "London", "tempC": 11.5, "conditions": "rain"}. - Configuration files. A Node.js project describes itself in
package.json, and PHP projects usecomposer.json. - Structured data in web pages. Google recommends JSON-LD, which is JSON inside a
<script>tag, for describing a page to search engines. Our schema generator writes it for you. - Login tokens. The middle part of a JSON Web Token is JSON encoded in Base64url; how to decode a JWT safely shows what's inside one.
- Databases and logs. PostgreSQL has
jsonandjsonbcolumn types, MongoDB stores records in BSON, a binary format modelled on JSON, and many servers write one JSON object per log line so the logs can be searched by field. - Data exports. Spreadsheet-style data usually leaves a system as CSV, but anything with nested parts (an order with several items, a user with several addresses) is easier to export as JSON. Our CSV to JSON converter turns a flat table into a JSON array in the browser; it reads number-like values as numbers, so a ZIP code such as 02134 comes out as 2134 unless you fix that column by hand.
What is JSON in coding?
To a program, JSON arrives as one long piece of text. Before the program can use it, it parses the text into its own objects and lists, and when it sends data back it turns them into text again. Every common language has a function pair for this:
// JavaScript
const user = JSON.parse('{"name": "Ada", "born": 1815}');
user.born + 1; // 1816
JSON.stringify(user); // '{"name":"Ada","born":1815}'
# Python
import json
user = json.loads('{"name": "Ada", "born": 1815}')
user["born"] + 1 # 1816
json.dumps(user) # '{"name": "Ada", "born": 1815}'
The two languages print the same data with different spacing (Python adds a space after each colon and comma), and both versions are valid JSON. Whitespace between values never changes the meaning, which is why a formatter can add or remove it freely.
JSON vs XML vs CSV for the same record
Here is one small record written three ways, with the size of each in bytes:
JSON (44 bytes):
{"name":"Ada","city":"London","active":true}
XML (73 bytes):
<person><name>Ada</name><city>London</city><active>true</active></person>
CSV (32 bytes, including the header line):
name,city,active
Ada,London,true
XML is the longest because every name appears twice, in an opening and a closing tag. CSV is the shortest but can only hold flat rows, so the languages list and address object from the earlier example have no natural place in it. JSON sits in between and handles nesting. If you're choosing between JSON and CSV for a real export, JSON vs CSV: which format to use goes through the trade-offs.
What is a JSON file, and how do you open one?
A JSON file is a plain-text file with the .json extension that holds one JSON value, nearly always an object or an array. Nothing in it is binary, so you can open it in any text editor:
- On Windows, right-click the file, choose Open with, then Notepad. On a Mac, open it with TextEdit.
- Drag it into Firefox, which shows JSON in a built-in viewer with collapsible sections. Most other browsers show the raw text.
- To see a table instead, Excel for Windows can import a JSON file through Data, Get Data, From File, From JSON.
To create a JSON file, type or paste the JSON into a plain-text editor and save it with a .json extension in UTF-8. Word processors such as Word add formatting and curly quotes, and curly quotes break JSON. A minified file is hard to read in Notepad because it is one long line; paste it into a formatter and it comes back indented. How to format JSON in your browser covers that step.
JSON-LD, JSON Schema, JSONB and other relatives
Search for what is JSON and you also run into several formats and tools that carry "JSON" in their name. They all build on the same syntax:
| Name | What it is |
|---|---|
| JSON-LD | JSON with agreed keys such as @context and @type for linked data, a W3C Recommendation. It is the format of schema.org markup in web pages. |
| JSON Schema | A JSON document that describes what other JSON must contain: required keys, types and allowed values. Programs use it to reject data that is well formed but wrong. |
| JSONB | PostgreSQL's binary storage type for JSON. It keeps the data, but drops extra whitespace, does not keep key order, and keeps only the last value of a duplicate key. |
| JSONC | "JSON with comments", used by VS Code for its settings files. Standard parsers reject it. |
| JSON Lines | One complete JSON value per line, often with a .jsonl extension. Common for logs and large exports because a program can read it line by line. |
How to look at JSON yourself
- Open our free JSON formatter. It runs in your browser, so nothing you paste is uploaded.
- Paste some JSON into the Input JSON box, or click Try Example to load a sample.
- Click Format / Prettify. The output is indented with 2 spaces by default; you can switch to 4 spaces or tabs.
- Scroll to the JSON Explorer under the output. It labels every value with its type (string, number, boolean, null, object or array), and you can open and close each object and array, which is a quick way to learn the six types above.
- If the input has a mistake, the tool shows "Invalid JSON" and your browser's description of the problem instead of an output.
Frequently asked questions
Is JSON only for JavaScript?
No. The syntax came from JavaScript, but ECMA-404 describes JSON as a "language-independent syntax". Python ships with a json module, and PHP's JSON extension is part of the core, so it is always enabled. In languages such as Java and C++, developers usually add a JSON library.
Is JSON better than XML?
For typical web data it's shorter (44 bytes against 73 in the example above) and maps directly onto the objects and lists programs already use. XML still suits some jobs: it has attributes, comments and mixed text and markup, and formats such as XML sitemaps and RSS feeds are built on it.
What is a .json file?
A plain-text file that holds one JSON value, usually an object or an array. Any text editor can open it. RFC 8259 requires UTF-8 encoding when JSON is exchanged between systems, which is why accented letters and emoji generally come through intact.
Can JSON contain comments?
No. Standard parsers reject // and /* */. Some projects add a field such as "_comment" instead, and some config files use JSON5, an extension that allows comments, but a strict JSON parser won't read JSON5.