Quick JSON tips

Just a few words about JSON format. The format of the assignments JSON file will make more sense after we’ve learned a little bit of JavaScript (in the next 3 weeks). For this assignment I’m not really asking you to understand the format, but you do have to obey the syntax rules or the assignment tests will fail. JSON is a portable data format used for moving data from one source to another. It is what is called a “key-value datastore” – a JSON file consists of “keys”, or names, and associated “values”. The relationship is represented by a : – os a single key-value pair is written as key: value.

What I wrote above is almost true. However, there are a few more rules to follow:

  • in JSON, the key name must be enclosed in double quotation marks
  • the value must be either a plain number, the special words true or false, or any sequence of characters surrounded by quotation marks (actually, it’s more complicated than that, but for this assignment let’s not say any more)
  • key-value pairs are separated from each other by commas
  • the whole JSON object must be surrounded by curly braces

So a real JSON file – the model for what you must produce – will look like this:

{
  "firstName": "Korra",
  "lastName": "",
  "nickName": "Avatar",
  "privateName": false,
  "picture": "https://upload.wikimedia.org/wikipedia/en/d/db/Korra_The_Legend_of_Korra.jpg",
  "privatePicture": false,
  "email": "korra_avatar@@utoronto.ca",
  "privateEmail": true,
  "github": "korra",
  "privateGithub": false,
  "superpower" : "Master of All Four Elements",
  "academicinterests": "Comparative Ancient Greek and Chinese Cosmology; Conservation Principles in Physical and Religious Systems"
}

MOST STUDENTS MAKE SYNTAX ERRORS WHEN THEY ARE STARTING OUT. Please don’t be discouraged by this. Just keep on plugging away.