AI Computer Science Academy · Faisalabad

JavaScript Essentials

Recover from bad JSON

Task 56 of 56 JavaScript Capstone: real browser patterns
All tasks
Read first Task 56

Recover from bad JSON

`JSON.parse` throws on broken text. A `try/catch` turns a crash into a useful message, which is what a form should show.

Task

Task: Recover from bad JSON. What does this program print?

The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.

What you start with
const inputs = ['{"fee": 10000}', 'not json'];

for (const text of inputs) {
  try {
    const data = JSON.parse(text);
    console.log('Fee:', data.fee);
  } catch (error) {
    console.log('Bad input:', text);
  }
}
JavaScript 1 automatic check Capstone: real browser patterns
Code editor Ctrl + Enter runs
Run your code to see the output and the checks.
Your result

Submit your code to see results

Write your code in the middle column and press Run code.

Checks on this task:

  • Check 1

Track progress

0 of 56 tasks complete

Next task unlocks when every check passes.

Sign in to keep your code and certificates.

Next task (pass every check first)