Skip to main content

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. 1

    Turn an object into text

    easy10 min

    Stringify a person object and show the text.

  2. 2

    Turn text into an object

    easy10 min

    Parse a JSON string and show the name from it.

  3. 3

    Round trip an object

    easy10 min

    Stringify then parse an object and show the year.

  4. 4

    Make a deep copy

    easy10 min

    Copy a nested object through JSON, change the copy, and show the original city.

  5. 5

    Handle invalid JSON

    medium10 min

    Wrap a parse in a try block and report when the text is not valid.

Find the bug(5)

  1. 1

    Fix parse used instead of stringify

    easy8 min

    An object needs turning into text, not the other way round.

  2. 2

    Fix the text used without parsing

    easy8 min

    A JSON string has no properties until it is parsed.

  3. 3

    Fix the shallow copy

    easy8 min

    Spread shares the nested object, so the original was changed too.

  4. 4

    Fix the unguarded parse

    easy8 min

    Invalid text throws, so the parse needs a try block.

  5. 5

    Fix the single quotes in the JSON

    easy8 min

    JSON 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