JavaScript JSON — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript JSON lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Turn an object into text
easy10 minStringify a person object and show the text.
- 2
Turn text into an object
easy10 minParse a JSON string and show the name from it.
- 3
Round trip an object
easy10 minStringify then parse an object and show the year.
- 4
Make a deep copy
easy10 minCopy a nested object through JSON, change the copy, and show the original city.
- 5
Handle invalid JSON
medium10 minWrap a parse in a try block and report when the text is not valid.
Find the bug(5)
- 1
Fix parse used instead of stringify
easy8 minAn object needs turning into text, not the other way round.
- 2
Fix the text used without parsing
easy8 minA JSON string has no properties until it is parsed.
- 3
Fix the shallow copy
easy8 minSpread shares the nested object, so the original was changed too.
- 4
Fix the unguarded parse
easy8 minInvalid text throws, so the parse needs a try block.
- 5
Fix the single quotes in the JSON
easy8 minJSON requires double quotes around every key and string.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace