JSON files: structure

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

JSON files: structure

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which JSON object is written correctly?
A {"name": "Ava", "year": 12}
B {name = "Ava", year = 12}
2. In the JSON {"name": "Ava", "year": 12}, what is "year"?
A A key, paired with the value 12
B A value, paired with the key 12
3. Which brackets does JSON use to hold a list of items?
A Curly braces { }
B Square brackets [ ]
4. A student file needs to hold many students, each with a name and a year level. Which structure fits best?
A An array of objects: [{"name": "Ava"}, {"name": "Liam"}]
B One object that repeats the key: {"name": "Ava", "name": "Liam"}
5. Which line is valid JSON?
A {'student': {'name': 'Ava', 'year': 12}}
B {"student": {"name": "Ava", "year": 12}}

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1{"name": "Ava", "year": 12} AThere is no comma between the two key-value pairs, so the file is invalid and a program cannot read it.
2"students": [{"name": "Ava"}, {"name": "Liam"}] BA JSON object: curly braces hold key-value pairs separated by commas
3JSON can nest one object inside another to group related data C[{"item": "Pencil"}, {"item": "Notebook"}]
4JSON stores a list of records as an array of objects, while XML needs repeated opening and closing tags D{"student": {"name": "Ava", "house": "Red"}}
5{name: "Ava", "year": 12} EA key whose value is an array (list) of objects, written in square brackets
6{"name": "Ava" "year": 12} FThe key name is not wrapped in double quotes. Every JSON key must be a double-quoted string.

Definitions

{"name": "Ava", "year": 12}

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
{"name": "Ava", "year"_ 12}
2.
_"name": "Ava", "year": 12}
3.
{"students": _ {"name": "Ava"}, {"name": "Liam"}]}
4.
{"name": "Ava", "address": _"city": "Cairns"}}
5.
XML: <year>12</____>

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A {
B "name" = "Ava",
C "year": 12
D }
Question 2
A {
B student: "Liam",
C "house": "Blue"
D }
Question 3
A {
B "id": 7,
C "points": 120,
D "house": "Red",
E }
Question 4
A {
B "name": "Mia",
C 'year': 11
D }
Question 5
A {
B "name": "Noah",
C "marks": {88, 74, 91}
D }

Answer Key

JSON files: structure
Section A: Quick Questions
Q1
A — {"name": "Ava", "year": 12}
Q2
A — A key, paired with the value 12
Q3
B — Square brackets [ ]
Q4
A — An array of objects: [{"name": "Ava"}, {"name": "Liam"}]
Q5
B — {"student": {"name": "Ava", "year": 12}}
Section B: Match the Pairs
Q1
{"name": "Ava", "year": 12} → A JSON object: curly braces hold key-value pairs separated by commas
Q2
"students": [{"name": "Ava"}, {"name": "Liam"}] → A key whose value is an array (list) of objects, written in square brackets
Q3
JSON can nest one object inside another to group related data → {"student": {"name": "Ava", "house": "Red"}}
Q4
JSON stores a list of records as an array of objects, while XML needs repeated opening and closing tags → [{"item": "Pencil"}, {"item": "Notebook"}]
Q5
{name: "Ava", "year": 12} → The key name is not wrapped in double quotes. Every JSON key must be a double-quoted string.
Q6
{"name": "Ava" "year": 12} → There is no comma between the two key-value pairs, so the file is invalid and a program cannot read it.
Section C: Definitions
Q1
{"name": "Ava", "year": 12} — JSON stores data as key-value pairs inside curly braces, with lists in square brackets. Objects can nest inside each other, so programs can read it easily. It is a lighter alternative to XML.
Section D: Fill in the Blanks
Q1
{"name": "Ava", "year": 12}
Q2
{"name": "Ava", "year": 12}
Q3
{"students": [ {"name": "Ava"}, {"name": "Liam"}]}
Q4
{"name": "Ava", "address": {"city": "Cairns"}}
Q5
XML: <year>12</year>
Section E: Spot the Error
Q1
B — A JSON key and its value are separated by a colon, not an equals sign. It should be "name": "Ava",
Q2
B — JSON keys must be wrapped in double quotes. It should be "student": "Liam",
Q3
D — The last key-value pair must not end with a comma, because nothing follows it before the closing brace. It should be "house": "Red"
Q4
C — JSON requires double quotes around keys. Single quotes are not valid. It should be "year": 11
Q5
C — A list of values in JSON goes in square brackets, not curly braces. It should be "marks": [88, 74, 91]