What Is JSON? A Beginner's Guide with Examples
If you're learning programming, building a website or working with an API, you'll meet JSON almost immediately. It is the most common format for sending data between apps and servers. The good news is that it is simple to learn. This guide covers everything a beginner needs.
What does JSON stand for?
JSON means JavaScript Object Notation. It started as a way to write data in JavaScript, but today almost every language can read and write it: Python, Java, C#, PHP, Go and more.
A simple example
{
"name": "Juan Dela Cruz",
"age": 21,
"isEnrolled": true,
"course": "BS Computer Engineering",
"subjects": ["Programming 1", "Data Structures", "Networking"],
"address": {
"city": "Santiago City",
"province": "Isabela"
}
}
This describes one student. Each piece of data is a key (in quotes) followed by a colon and a value.
The six JSON data types
| Type | Example |
|---|---|
| String | "Hello" (always double quotes) |
| Number | 21, 3.14, -5 |
| Boolean | true or false |
| Null | null (no value) |
| Array | ["a", "b", "c"] |
| Object | {"key": "value"} |
Arrays and objects can contain each other, which lets JSON describe complex data like a list of students, each with a list of grades.
The most common JSON errors
- Single quotes:
{'name': 'Ana'}is invalid. Use double quotes. - Trailing commas:
{"a": 1, "b": 2,}is invalid because of the last comma. - Unquoted keys:
{name: "Ana"}works in JavaScript code but not in JSON. - Comments: JSON doesn't allow
//or/* */comments. - Missing brackets: every
{needs a}and every[needs a].
Paste your data into our JSON Formatter to find the exact error. Click Beautify to indent messy JSON so it's easy to read, or Minify to remove spaces before sending it.
Where JSON is used
- Web APIs: when an app requests weather, prices or user data, the server usually replies with JSON.
- Configuration files: such as
package.jsonin Node.js projects or settings in VS Code. - Databases: document databases like MongoDB store JSON-like data.
- Data exchange: exporting and importing data between systems.
Reading JSON in code
In JavaScript:
const student = JSON.parse(text); // text → object
console.log(student.name);
const text2 = JSON.stringify(student); // object → text
In Python:
import json
student = json.loads(text)
print(student["name"])
JSON vs. XML
Before JSON became popular, many systems used XML. JSON is shorter, easier for people to read, and maps directly to the objects and lists in most programming languages, which is why most modern APIs prefer it.
Practice tip
Try writing a JSON object that describes your own class schedule: an array of subjects, each with a name, room, day and time. Then validate it in the JSON Formatter. Fixing your own errors is the fastest way to learn the rules.