forked from lsvekis/JavaScript-Exercises-Book
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSON Handling
More file actions
14 lines (14 loc) · 883 Bytes
/
JSON Handling
File metadata and controls
14 lines (14 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Objective: Learn to parse JSON strings and stringify JavaScript objects.
// 1. Declare a JSON string representing an object with name and age properties.
let jsonString = '{"name": "Alex", "age": 30}';
// 2. Parse the JSON string into a JavaScript object.
let personObject = JSON.parse(jsonString);
// 3. Print the name and age of the person to the console.
console.log("Name: " + personObject.name + ", Age: " + personObject.age);
// 4. Modify the age property of the person object.
personObject.age = 31;
// 5. Stringify the modified object back into a JSON string.
let modifiedJsonString = JSON.stringify(personObject);
// 6. Print the modified JSON string to the console.
console.log("Modified JSON: " + modifiedJsonString);
// Exercise: Create a more complex JSON string representing an array of objects, parse it, modify one of the objects, and stringify it back into JSON.