CH6: What Is JSON (JavaScript Object Notation) Flashcards
(7 cards)
What is JSON and what is it used for?
JSON stands for JavaScript Object Notation. It’s a simple and human-readable way to store and share data between systems, especially websites and apps.
Example:
A website might save a user profile like this: { “name”: “Alice”, “age”: 25, “isStudent”: true }
What does JSON data look like?
JSON data is made of keys and values. Keys are always in double quotes, and values can be text, numbers, true/false, or other objects and lists.
Example:
{ “name”: “Alice”, “age”: 25 } means the user’s name is Alice and her age is 25.
What are the two main structures used in JSON?
JSON uses:
- Objects: key-value pairs inside curly braces {}
- Arrays: ordered lists inside square brackets []
Example:
Object: { “city”: “Paris” } — Array: [“Paris”, “London”, “Rome”]
What kinds of values can JSON store?
JSON can store:
- Strings: “hello”
- Numbers: 123
- Booleans: true or false
- Null values: null
- Arrays: [1, 2, 3]
- Objects: { “key”: “value” }
Example:
{ “isOnline”: true, “score”: 100 }
What are some syntax rules for writing JSON correctly?
Some important rules:
- All keys must be in double quotes
- Objects use {}, arrays use []
- Items are separated with commas
- Files usually end in .json
Example:
This is valid: { “age”: 30, “name”: “Bob” } — don’t forget the commas and quotes!
Why is JSON important and widely used?
JSON is popular because it’s:
- Easy to read and write
- Easy for computers to use
- Small in size, so it’s fast online
- Works with many languages like JavaScript, Python, and more
Example:
Unlike XML, JSON doesn’t need extra tags and is cleaner to read.
How is JSON used in real-world situations like APIs?
When websites or apps talk to each other, they often use JSON to send and get data. This is called an API.
Example:
A weather app might send: { “city”: “New York” }, and get back: { “temperature”: 72, “status”: “sunny” }