• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger●JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed○Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes○Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

JSON

Mission: Artist Profile Lab

The artist profile may need to travel as text between programs. Turn an object into JSON text, parse a response, and compare a copy with its original in the Console.

JSON (JavaScript Object Notation) is the standard format for exchanging data between systems — APIs, config files, local storage. It looks like a JavaScript object literal but with stricter rules.

JSON rules

  • All keys must be quoted with double quotes.
  • Values can be: string, number, boolean, null, array, or object.
  • No functions, undefined, or comments.
json
{
    "name": "Alice",
    "age": 30,
    "skills": ["JavaScript", "HTML"],
    "address": { "city": "London" }
}

JSON.stringify() — object → string

javascript
const recipe = { dish: "Soup", servings: 4 };
const recipeText = JSON.stringify(recipe);
const weather = JSON.parse("{\"condition\":\"clear\",\"temp\":19}");
console.log(recipeText, weather.condition);

JSON.parse() — string → object

javascript
const data = '{"name":"Bob","score":95}';
const obj = JSON.parse(data);
console.log(obj.name);  // "Bob"
console.log(obj.score); // 95

Your Task

  1. Given the object user = { name: "Sam", level: 5, active: true }, serialize it to a JSON string and store in userJson.
  2. Parse the string apiResponse = '{"status":"ok","count":42}' and store the result in parsed.
  3. Write deepClone(obj) using JSON.parse(JSON.stringify(obj)) for JSON-safe data only; functions, undefined, Date, and BigInt are not preserved.
  4. Set only the copy’s nested.b to 99, leaving the original unchanged.
  5. Log Sam is level 5 | status: ok, count: 42 on its own Console line.
Hint 1
1 / 3
HINT 1

Use JSON.stringify(obj) to convert an object to a JSON string.

HINT 2

Use JSON.parse(str) to convert a JSON string back to an object.

HINT 3

JSON.stringify accepts a second argument (replacer) and third (indent spaces).

Loading editor…
Press Run to execute your code.
READY
intercourses
javascript