Introduction to JSON - potatoscript/json GitHub Wiki

👀 What is JSON?

JSON stands for JavaScript Object Notation. It's a fancy name, right? But don’t worry, it’s much easier to understand than it sounds! Imagine you have a box 📦 where you can keep all sorts of information. JSON is like that box — it stores information in a way that both humans and computers can understand. 🌍💻

Think of it as the language that helps computers talk to each other and share information. It's like writing down a list of things you need 📝 that both you and your friend can easily read and understand.


🌈 Why Do We Need JSON?

Let's imagine you want to send a letter 📬 to your friend telling them about your favorite things. But wait... how will you make sure your friend understands your letter? You need to write it in a way that is clear and simple!

That's where JSON comes in. It's like a special way to write down information that both you and your friend can read and understand easily. So, if you were a computer, you could send that letter in JSON, and your friend (another computer) could read it instantly! 📡💬


🧩 JSON Structure – How Does It Look?

Let’s look at a JSON object 👇. This is how a "letter" (or a JSON object) looks:

{
    "name": "Lucy",
    "age": 10,
    "favoriteColor": "Blue",
    "hobbies": ["Reading", "Coding", "Running"]
}

In this letter (or JSON object), we have:

  • Name: Lucy (A person's name)
  • Age: 10 (How old Lucy is)
  • Favorite Color: Blue (Her favorite color)
  • Hobbies: ["Reading", "Coding", "Running"] (Things Lucy likes to do)

🖊️ JSON Syntax Rules

Just like writing a letter, JSON has rules you must follow to make sure it’s easy to understand.

Here are the main rules to follow when writing JSON:

  1. Curly Braces { }: These are used to start and end your "letter" or object. It's like the envelope of your letter! ✉️

  2. Quotes "": Every piece of information (like a name or age) must be inside double quotes. This keeps things neat! 🧹

  3. Colon :: This shows that you're giving information. For example, "name": "Lucy" means the "name" is Lucy. 🏷️

  4. Comma ,: Use a comma to separate different pieces of information. But remember, no comma after the last one! ⚖️


🎡 Let’s Build Our Own JSON Object!

Let’s build a JSON object for a dog 🐶. We’ll follow the same rules!

{
    "dogName": "Max",
    "age": 3,
    "favoriteFood": "Bones",
    "isFriendly": true,
    "favoriteToys": ["Ball", "Frisbee"]
}

Now, let’s break it down:

  • dogName: Max (The dog’s name)
  • age: 3 (The dog’s age)
  • favoriteFood: Bones (What the dog loves to eat)
  • isFriendly: true (Yes, this dog is friendly!)
  • favoriteToys: ["Ball", "Frisbee"] (What the dog likes to play with)

📦 Working with Arrays in JSON

JSON isn’t just about single items — you can also store groups of things (like a list of favorite toys, for example). This is done using arrays. An array is like a shopping list or a list of your friends' names! 📝

Here’s an example of a JSON object that has an array:

{
    "name": "Lucy",
    "friends": ["Anna", "Tom", "Jill", "Mike"]
}

In this example:

  • friends: ["Anna", "Tom", "Jill", "Mike"] is an array that lists all Lucy’s friends.

🔍 JSON Example: Your School Information

Now, let's make it more fun! Let’s create a JSON object about a school 🏫. You’re going to help!

{
    "schoolName": "Sunnydale School",
    "location": "Fukuoka",
    "students": 500,
    "subjects": ["Math", "Science", "Art"],
    "isOpen": true
}

This JSON object has:

  • schoolName: Sunnydale School
  • location: Fukuoka
  • students: 500
  • subjects: ["Math", "Science", "Art"]
  • isOpen: true (Yes, the school is open today!)

🚀 JSON for Computers and Websites

Now that you know the basics, JSON is super useful for computers and websites! Here’s how:

  • Websites send JSON to share information like weather data 🌦️ or news updates 📰.
  • Apps use JSON to save your preferences, like your favorite color 🎨 or high scores 🏅 in games!

For example, when you open an app that shows you the weather, the app might get something like this in JSON:

{
    "city": "Fukuoka",
    "temperature": 22,
    "forecast": "Sunny"
}

The app uses that JSON to display 22°C and Sunny for Fukuoka! 🌞