

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
The JSON.parse() method takes a JSON string as input and constructs the JavaScript value/object described by the string. This allows us to work with the JSON as an object!
const json = '{"title": "Avengers Endgame", "Rating":4.7, "inTheaters":false}';
const obj: Movie = JSON.parse(json);
console.log(obj.title);
// Avengers Endgame
It's common for developers to write local tests using mock (or fake) data that looks like real data. Let's ensure that the JSON format that the backend developers at Jello provided to us is valid JSON! It would be a shame to write a bunch of code just to find out the backend has given us the wrong format.
Complete the parseProject function. Use a try/catch block to safely call JSON.parse on the projectString provided. Keep in mind that JSON.parse throws an error if it is given a string that isn't valid JSON.
If you can parse the string successfully, use the printProjectObj function to print the parsed object. If an error was thrown, just log invalid json string to the console.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution