Challenge - 5 Problems
JSON Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this JSON parsing code?
Consider this JavaScript code that parses a JSON string and accesses a property.
What will be logged to the console?
What will be logged to the console?
Rest API
const jsonString = '{"name": "Alice", "age": 30}';
const obj = JSON.parse(jsonString);
console.log(obj.name);Attempts:
2 left
💡 Hint
Think about what JSON.parse does to a JSON string.
✗ Incorrect
JSON.parse converts a JSON string into a JavaScript object. Accessing obj.name returns the value 'Alice'.
🧠 Conceptual
intermediate1:30remaining
Why is JSON preferred as a standard format in REST APIs?
Which of the following is the main reason JSON is widely used as a standard format in REST APIs?
Attempts:
2 left
💡 Hint
Think about readability and compatibility.
✗ Incorrect
JSON is text-based, easy for humans to read and for machines to parse, making it ideal for data exchange.
🔧 Debug
advanced2:00remaining
What error does this JSON parsing code produce?
What error will this JavaScript code produce when run?
Rest API
const badJson = '{name: "Bob", age: 25}';
const data = JSON.parse(badJson);Attempts:
2 left
💡 Hint
Check the JSON string format carefully.
✗ Incorrect
JSON keys must be in double quotes. Missing quotes cause a SyntaxError during parsing.
❓ Predict Output
advanced2:30remaining
What is the output of this REST API JSON response handling code?
Given this JavaScript code snippet that fetches JSON data from an API, what will be logged?
Rest API
async function getUser() { const response = await fetch('https://api.example.com/user'); const data = await response.json(); console.log(data.active); } // Assume the API returns: {"id": 1, "name": "Eve", "active": false} getUser();
Attempts:
2 left
💡 Hint
Look at the value of the 'active' property in the JSON response.
✗ Incorrect
The API returns active as false, so logging data.active outputs false.
🚀 Application
expert2:00remaining
How many keys are in this JSON object after parsing?
Consider this JSON string and the code that parses it.
How many keys does the resulting object have at the top level?
How many keys does the resulting object have at the top level?
Rest API
const jsonStr = '{"user": {"id": 10, "name": "Sam"}, "status": "active", "roles": ["admin", "user"]}';
const obj = JSON.parse(jsonStr);
console.log(Object.keys(obj).length);Attempts:
2 left
💡 Hint
Count only the keys at the top level of the object.
✗ Incorrect
The top-level keys are 'user', 'status', and 'roles', totaling 3 keys.