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.
Why this works
Checks on this task:
- Check 1
One correct answer:
Track progress
0 of 56 tasks complete
Finish the track
Next task unlocks when every check passes.
Sign in to keep your code and certificates.
Next task (pass every check first)
Hint
Ask yourself: Task: Recover from bad JSON. What does this program print?