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:

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.

TypeExampleNotes
string"ঢাকা", "Rahim"Double quotes only. Any Unicode text, including Bangla.
number42, -3.5, 1.2e6No quotes, no leading zeros, no NaN or Infinity.
booleantrue, falseLowercase, no quotes.
nullnull“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 objectIn JSON
Unquoted keys: { name: "Rahim" }Keys must be in double quotes
Single quotes: 'Dhaka'Double quotes only
Trailing comma after the last itemNot allowed
Comments // and /* */Not allowed
undefined, functions, Date, NaNNot 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

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:

See your JSON as a tree. Paste any JSON into the formatter to indent it, validate it and click through nested objects without uploading anything. Try it now

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.

JSON কী? নতুনদের জন্য সহজ গাইড

প্রায় যেকোনো ওয়েবসাইটের Network ট্যাব খুলুন, কোনো পেমেন্ট গেটওয়ে বা কুরিয়ারের API কল করুন, কিংবা একটা package.json ফাইল খুলে দেখুন — সবখানে একই জিনিস চোখে পড়বে: কার্লি ব্রেস, স্কয়ার ব্র্যাকেট আর ডাবল কোটে ভরা লেখা। এটাই JSON। ডেভেলপার হিসেবে যাত্রা শুরু করলে প্রতিদিনই আপনাকে JSON পড়তে ও লিখতে হবে। তাই শুরুতেই এটা ঠিকমতো বুঝে নেওয়া ভালো — বিশেষ করে সেই কয়েকটা কড়া নিয়ম, যেগুলোতে প্রায় সব নতুন ডেভেলপারই একবার না একবার আটকে যান।

এক কথায় JSON

JSON (JavaScript Object Notation) হলো গোছানো ডেটা রাখার একটি প্লেইন-টেক্সট ফরম্যাট। এর জন্ম JavaScript-এর অবজেক্ট লেখার ধরন থেকে, কিন্তু এখন Python, PHP, Java, Go, C#, Dart — সব বড় ভাষাই JSON পড়তে ও লিখতে পারে। দুটি ছোট স্ট্যান্ডার্ড, RFC 8259 ও ECMA-404, এটিকে সংজ্ঞায়িত করে, আর পুরো ব্যাকরণ এক পাতায় এঁটে যায়। ফাইলের নাম সাধারণত .json দিয়ে শেষ হয়, আর API পাঠায় Content-Type: application/json হেডারসহ।

JSON কেন এত জনপ্রিয় হলো? মানুষের পক্ষে পড়া সহজ, প্রোগ্রামের পক্ষে পার্স করা সহজ, আর প্রতিটি ভাষায় আগে থেকেই যে দুটি ডেটা স্ট্রাকচার আছে — লিস্ট আর কী–ভ্যালু ম্যাপ — JSON সরাসরি সেগুলোর সাথে মিলে যায়।

মূল সিনট্যাক্স

নিচে একটি ছোট কিন্তু সম্পূর্ণ JSON ডকুমেন্ট:

{
  "name": "Rahima Akter",
  "city": "Chattogram",
  "age": 27,
  "verified": true,
  "skills": ["JavaScript", "SQL"],
  "manager": null
}

নিয়মগুলো, যা ওপরের উদাহরণেই দেখা যাচ্ছে:

ছয় ধরনের ভ্যালু

JSON-এর প্রতিটি ভ্যালু ঠিক এই ছয় ধরনের যেকোনো একটি। এর বাইরে আর কিছু নেই — তারিখ নেই, কমেন্ট নেই, ফাংশন নেই।

টাইপউদাহরণখেয়াল রাখুন
string"ঢাকা", "Rahim"শুধু ডাবল কোট। বাংলাসহ যেকোনো ইউনিকোড লেখা চলবে।
number42, -3.5, 1.2e6কোট নয়, শুরুতে বাড়তি শূন্য নয়, NaN বা Infinity নয়।
booleantrue, falseছোট হাতের অক্ষরে, কোট ছাড়া।
nullnull“কোনো মান নেই”। ছোট হাতের অক্ষরে।
object{"a": 1}ক্রমহীন কী–ভ্যালু জোড়া।
array[1, "two", false]ক্রমানুসারে সাজানো তালিকা; ভিন্ন ভিন্ন টাইপ মেশানো যায়।

স্ট্রিংয়ের ভেতরে কিছু অক্ষর ব্যাকস্ল্যাশ দিয়ে এসকেপ করতে হয়: ডাবল কোটের জন্য \", ব্যাকস্ল্যাশের জন্য \\, নতুন লাইনের জন্য \n আর ট্যাবের জন্য \t। যেকোনো অক্ষর \u আর চারটি হেক্স ডিজিট দিয়েও লেখা যায় — যেমন "র" হলো বাংলা অক্ষর র।

নেস্টিং: অবজেক্টের ভেতরে অ্যারে, অ্যারের ভেতরে অবজেক্ট

অবজেক্ট আর অ্যারে একে অপরের ভেতরে যত গভীরে ইচ্ছা থাকতে পারে। বাস্তব জগতের ডেটা JSON এভাবেই বর্ণনা করে। বাংলাদেশের একটি অনলাইন শপ একটি অর্ডারের জন্য যেমন রেসপন্স দিতে পারে:

{
  "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
}

বাইরে থেকে ভেতরের দিকে পড়ুন: পুরো অর্ডারটি একটি অবজেক্ট; customer একটি অবজেক্ট, যার ভেতরে আরেকটি অবজেক্ট (address); items হলো অবজেক্টের একটি অ্যারে, প্রতিটি পণ্যের জন্য একটি করে। JavaScript-এ প্রথম আইটেমের দাম পেতে লিখবেন order.items[0].unit_price — অ্যারের গোনা শুরু হয় 0 থেকে।

সিদ্ধান্তগুলো খেয়াল করুন: ফোন নম্বর আর পোস্টকোড সংখ্যা নয়, স্ট্রিং — কারণ এগুলো পরিচয়সূচক। সংখ্যা হিসেবে লিখলে 01712345678-এর শুরুর শূন্য হারিয়ে যেত (আর সেটা বৈধ JSON-ও নয়)। তারিখটি ঢাকার অফসেট +06:00-সহ একটি ISO 8601 স্ট্রিং, কারণ JSON-এ তারিখের আলাদা কোনো টাইপ নেই।

JSON আর JavaScript অবজেক্ট এক জিনিস নয়

নতুনদের সবচেয়ে বড় বিভ্রান্তি এটাই। JSON দেখতে JavaScript-এর মতো, কিন্তু এটি আরও কড়া নিয়মের, শুধুই লেখা-ভিত্তিক একটি ফরম্যাট। JavaScript অবজেক্ট থাকে মেমরিতে; JSON হলো একটি স্ট্রিং, যা আপনি পাঠান বা সেভ করেন।

JavaScript অবজেক্টে চলেJSON-এ
কোট ছাড়া কী: { name: "Rahim" }কী অবশ্যই ডাবল কোটে
সিঙ্গেল কোট: 'Dhaka'শুধু ডাবল কোট
শেষ আইটেমের পরে কমাচলবে না
কমেন্ট // ও /* */চলবে না
undefined, ফাংশন, Date, NaNপ্রকাশ করা যায় না

দুটির মধ্যে আসা-যাওয়া করা হয় দুটি বিল্ট-ইন ফাংশন দিয়ে:

// লেখা → JavaScript ভ্যালু
const order = JSON.parse('{"total": 1310, "paid": false}');
console.log(order.total);          // 1310

// JavaScript ভ্যালু → লেখা (২ স্পেস ইনডেন্ট)
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"
// }

JSON.stringify কী করল দেখুন: Date হয়ে গেল ISO স্ট্রিং, আর যে কী-এর মান ছিল undefined, সেটা পুরোপুরি উধাও। অ্যারের ভেতরে থাকলে অবশ্য undefined আর NaN হয়ে যায় null। এরকম নিঃশব্দ রূপান্তর থেকেই “আমার ফিল্ডটা গেল কোথায়?” ধরনের অনেক বাগ তৈরি হয়।

Python-এ json মডিউল দিয়ে কাজটা একইভাবে হয়:

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))
# ensure_ascii=False না দিলে পাবেন "রহিম"

নতুনরা আর যেসব ভুল করেন

JSON কীভাবে দেখবেন ও ফরম্যাট করবেন

ব্যান্ডউইথ বাঁচাতে API সাধারণত JSON পাঠায় “minified” করে — স্পেস ছাড়া একটা লম্বা লাইন। মানুষের পক্ষে সেটা পড়া প্রায় অসম্ভব। কয়েকটা উপায় আছে:

আপনার JSON ট্রি আকারে দেখুন। যেকোনো JSON ফরম্যাটারে পেস্ট করে ইনডেন্ট, যাচাই আর নেস্টেড অবজেক্টগুলো ক্লিক করে ঘুরে দেখুন — কিছুই আপলোড হয় না। এখনই চেষ্টা করুন

প্রশ্নোত্তর

JSON ফাইলে কি কমেন্ট লেখা যায়?

না। স্ট্যান্ডার্ড JSON-এ কমেন্টের কোনো সিনট্যাক্স নেই, আর কড়া পার্সার // বা /* */ দেখলে বাতিল করে দেবে। কিছু টুল “JSONC” (কমেন্টসহ JSON) মেনে নেয়, যেমন VS Code-এর সেটিংস ফাইল, কিন্তু সেটা কোনো API-তে পাঠাবেন না। কনফিগে কমেন্ট দরকার হলে YAML ভেবে দেখুন।

দামের মতো জিনিস স্ট্রিং হবে না সংখ্যা?

যেগুলো দিয়ে হিসাব করবেন (দাম, পরিমাণ, মোট), সেগুলো সাধারণত সংখ্যা। যেগুলো শুধু দেখতে সংখ্যার মতো — ফোন নম্বর, পোস্টকোড, অ্যাকাউন্ট নম্বর, খুব লম্বা আইডি — সেগুলো স্ট্রিং রাখুন, যাতে শুরুর শূন্য আর প্রতিটি ডিজিট ঠিক থাকে।

null আর কী না থাকার মধ্যে পার্থক্য কী?

"coupon": null বলে “ফিল্ডটা আছে, কিন্তু এর কোনো মান নেই”; আর কী-টা বাদ দিলে কিছুই বলা হয় না। অনেক API দুটোকে আলাদাভাবে দেখে, বিশেষ করে রেকর্ড আপডেট করার সময়, তাই API-এর ডকুমেন্টেশন দেখে নিন।

JSON কি শুধু JavaScript-এর জন্য?

না। নামে JavaScript থাকলেও JSON কোনো নির্দিষ্ট ভাষার ওপর নির্ভরশীল নয়। প্রতিটি প্রচলিত ভাষায় এর জন্য বিল্ট-ইন বা স্ট্যান্ডার্ড লাইব্রেরি আছে।

Related guides

More free tools