Skip to main content

Task 15: Understanding JSON with JavaScript

Start with Thanksgivingโ€‹

  • With every breath of thankfulness, blessings multiply in unexpected ways.

  • Today, I choose joy over worry, peace over pressure, and contentment over comparison.

  • I declare that every blessing in my life multiplies as I remain thankful.

  • I declare that I walk in abundance, not because of what I have, but because of who I serve.

  • I am a vessel for miraclesโ€”because I choose to stay thankful, no matter the season.

  • I declare that my heart is full of gratitude and my mouth speaks life.

  • I declare that thankfulness opens doors no man can shut.

  • I declare that I am a magnet for miracles because I choose gratitude.

  • I declare that I will see Godโ€™s goodness in new ways this season.

  • I affirm that gratitude flows through every part of my being today.

๐Ÿ’ช Repeat daily, feel the power, and watch your success unfold!


๐Ÿ”น If you donโ€™t understand the task, watch the video above for the answer.


Taskโ€‹


โ€” JSON โœ… What is JSON? โœ… How does it look? โœ… How do we use JSON with JavaScript? โœ… Whatโ€™s the difference between an object and JSON? โœ… Real-life example and a hands-on mini project!

Letโ€™s get started! ๐Ÿš€

** Step 1: What is JSON?โ€‹

JSON stands for JavaScript Object Notation. Itโ€™s a way to store and exchange data โ€” especially between a server and your JavaScript app.โ€

  • Think of it as a universal language for sending data!

Step 2: What Does JSON Look Like?โ€‹

JSON looks like a JavaScript object but with double quotes around keys and string values.

let person = {
name: "Lukas",
age: 10,
isStudent: true
};

โœ… Same thing in JSON:

{
"name": "Lukas",
"age": 10,
"isStudent": true
}

Notice how the keys in JSON always use double quotes. Thatโ€™s the main difference!

Step 3: Using JSON in JavaScriptโ€‹

Letโ€™s say we received JSON data from a server. We can turn it into a JavaScript object using JSON.parse().

let jsonData = '{"name": "Lukas", "age": 10}';
let obj = JSON.parse(jsonData);

console.log(obj.name); // Lukas
console.log(obj.age); // 10

Step 4: Sending Data as JSONโ€‹

Letโ€™s say we want to send data to a server โ€” weโ€™ll turn our object into JSON using JSON.stringify().

let student = {
name: "Lukas",
grade: "5th"
};

let jsonToSend = JSON.stringify(student);
console.log(jsonToSend);

  • Output: {"name":"Lukas","grade":"5th"}

Step 5: JSON + Mini Task โ€” Build a Recipe Card! ๐Ÿ•๐Ÿ‘จโ€๐Ÿณโ€‹

Letโ€™s build a fun example. Weโ€™ll create a recipe object and convert it to JSON.

let recipe = {
title: "Mini Pizza",
ingredients: ["Dough", "Tomato Sauce", "Cheese"],
time: "20 minutes"
};

let recipeJSON = JSON.stringify(recipe);
console.log("๐Ÿ” Sending to server:", recipeJSON);

let received = JSON.parse(recipeJSON);
console.log("๐Ÿ“ฅ Back in JS:", received.title);

Recap: What Did We Learn?โ€‹

  • JSON is a lightweight way to store and exchange data
  • It looks like an object, but keys and strings use double quotes
  • Use JSON.parse() to turn JSON into JavaScript
  • Use JSON.stringify() to turn JavaScript into JSON
  • Great for APIs, databases, and web apps!