What is JSON? A beginner’s guide
Open the Network tab on almost any website, call any payment gateway or courier API, or look inside a package.json file, and you will see the same thing: text full of curly braces, square brackets and double quotes. That is JSON. If you are starting out as a developer, you will read and write it every single day, so it pays to understand it properly — including the few strict rules that trip up almost every beginner.
JSON in one sentence
JSON (JavaScript Object Notation) is a plain-text format for structured data. It was derived from JavaScript’s object syntax, but today every major language — Python, PHP, Java, Go, C#, Dart — can read and write it. It is defined by two short standards, RFC 8259 and ECMA-404, and the whole grammar fits on one page. Files usually end in .json, and APIs send it with the header Content-Type: application/json.
Why did it win? It is easy for humans to read, easy for programs to parse, and it maps directly onto the data structures every language already has: lists and key–value maps.
The basic syntax
Here is a small but complete JSON document:
{
"name": "Rahima Akter",
"city": "Chattogram",
"age": 27,
"verified": true,
"skills": ["JavaScript", "SQL"],
"manager": null
}
The rules, all of which you can see above:
- An object is wrapped in
{ }and holds key–value pairs separated by commas. - Each key is a string in double quotes, followed by a colon, then the value.
- There is no comma after the last item.
- Spaces, tabs and line breaks between items don’t matter. The same data on one line is equally valid.
The six value types
Every value in JSON is exactly one of these six types. There is nothing else — no dates, no comments, no functions.
| Type | Example | Notes |
|---|---|---|
| string | "ঢাকা", "Rahim" | Double quotes only. Any Unicode text, including Bangla. |
| number | 42, -3.5, 1.2e6 | No quotes, no leading zeros, no NaN or Infinity. |
| boolean | true, false | Lowercase, no quotes. |
| null | null | “No value”. Lowercase. |
| object | {"a": 1} | Unordered key–value pairs. |
| array | [1, "two", false] | Ordered list; items can be of mixed types. |
Inside strings, some characters must be escaped with a backslash: \" for a double quote, \\ for a backslash, \n for a new line and \t for a tab. Any character can also be written as \u plus four hex digits — for example "র" is the Bangla letter র.
Nesting: objects inside arrays inside objects
Objects and arrays can contain each other to any depth. That is how JSON describes real-world data. Here is the kind of response an online shop in Bangladesh might return for a single order:
{
"order_id": "BD-2026-004517",
"placed_at": "2026-09-27T10:30:00+06:00",
"status": "shipped",
"customer": {
"name": "Tanvir Hasan",
"phone": "01712345678",
"address": {
"area": "Mirpur 10",
"city": "Dhaka",
"postcode": "1216"
}
},
"items": [
{ "sku": "TSHIRT-M-BLUE", "title": "Cotton T-shirt", "qty": 2, "unit_price": 450 },
{ "sku": "MUG-01", "title": "Ceramic mug", "qty": 1, "unit_price": 350 }
],
"delivery_charge": 60,
"total": 1310,
"payment": { "method": "cod", "paid": false },
"coupon": null
}
Read it from the outside in: the whole order is an object; customer is an object containing another object (address); items is an array of objects, one per product. To get the price of the first item in JavaScript you would write order.items[0].unit_price — array positions start at 0.
Notice the choices: the phone number and postcode are strings, not numbers, because they are identifiers — as a number, 01712345678 would lose its leading zero (and is not even valid JSON). The date is an ISO 8601 string with the Dhaka offset +06:00, because JSON has no date type.
JSON is not a JavaScript object
This is the number one beginner confusion. JSON looks like JavaScript, but it is a stricter, text-only format. A JavaScript object lives in memory; JSON is a string you send or save.
| Allowed in a JavaScript object | In JSON |
|---|---|
Unquoted keys: { name: "Rahim" } | Keys must be in double quotes |
Single quotes: 'Dhaka' | Double quotes only |
| Trailing comma after the last item | Not allowed |
Comments // and /* */ | Not allowed |
undefined, functions, Date, NaN | Not representable |
You move between the two with two built-in functions:
// Text → JavaScript value
const order = JSON.parse('{"total": 1310, "paid": false}');
console.log(order.total); // 1310
// JavaScript value → text (2-space indentation)
const text = JSON.stringify({ city: "Dhaka", when: new Date(0), note: undefined }, null, 2);
console.log(text);
// {
// "city": "Dhaka",
// "when": "1970-01-01T00:00:00.000Z"
// }
Look at what JSON.stringify did: the Date became an ISO string, and the key whose value was undefined disappeared completely. In an array, undefined and NaN become null instead. Silent conversions like these are a common source of “where did my field go?” bugs.
Python works the same way with the json module:
import json
order = json.loads('{"total": 1310, "paid": false}')
print(order["paid"]) # False (JSON false → Python False)
print(json.dumps({"name": "রহিম"}, ensure_ascii=False, indent=2))
# without ensure_ascii=False you get "রহিম"
Other things beginners get wrong
"true"is nottrue. In quotes it is a string, and in JavaScript the string"false"is truthy. The same goes for"42"versus42.- Key order is not guaranteed. The standard treats objects as unordered. If order matters, use an array.
- Duplicate keys are legal-looking but unsafe: most parsers silently keep the last one.
- The top level can be any value. An array like
[1, 2, 3]or even a bare"hello"is a valid JSON document, though APIs usually return an object. - Encoding: JSON exchanged between systems must be UTF-8, so Bangla text works without any special handling.
How to view and format JSON
APIs usually send JSON “minified” — one long line with no spaces — to save bandwidth. That is unreadable for humans. You have a few options:
- In code:
JSON.stringify(value, null, 2)in JavaScript orjson.dumps(value, indent=2)in Python. - On the command line:
python -m json.tool data.jsonpretty-prints a file. - In your editor: VS Code’s “Format Document” command works on
.jsonfiles. - In the browser: paste it into an online formatter, which also tells you exactly where any syntax error is.
FAQ
Can I put comments in a JSON file?
No. Standard JSON has no comment syntax, and a strict parser will reject // or /* */. Some tools accept “JSONC” (JSON with comments), such as VS Code settings files, but don’t send it to an API. If a config needs comments, consider YAML.
Should numbers like prices be strings or numbers?
Quantities you calculate with (price, qty, total) are usually numbers. Identifiers that only look numeric — phone numbers, postcodes, account numbers, very long IDs — should be strings so leading zeros and exact digits are preserved.
What is the difference between null and a missing key?
"coupon": null says “this field exists and has no value”; leaving the key out says nothing at all. Many APIs treat them differently, especially when updating records, so check the API’s documentation.
Is JSON only for JavaScript?
No. Despite the name, JSON is language-independent. Every mainstream language has a built-in or standard library for it.