>_ IzzyLab

Hands-on task

This task is step 14 of the course “JSON, YAML and XML in the terminal”

Fix the dashboard JSON

medium~5 min

The dashboard won't load its layout: the file /srv/dashboard/widgets.json stopped being valid JSON after a manual edit. Find the syntax error with a parser and fix it without changing the data: the title, both widgets and the refresh interval must stay.

What you'll practise:
  • json
  • jq
  • validation
  • trailing comma
  • JSON arrays

Topic breakdown

A JSON parser doesn't forgive what people and JavaScript do: a dangling comma after the last element of an array […] or object {…} makes the whole document invalid, and the program can't read a single field. Spotting such a place by eye in a big file is hard, so it's fixed with a parser: jq (or python3 -m json.tool) reports the line and column where parsing broke — usually the character right after the error, a closing bracket for example. After the edit the same parser checks that the file parses again and the data in it is unchanged.

What's checked

  1. widgets.json is valid JSON
  2. the dashboard data is preserved

What it looks like