Comparing JSON and XML

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

Comparing JSON and XML

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which format is usually shorter for the same data?
A XML
B JSON
2. Which snippet is JSON?
A {"name": "Ava", "year": 12}
B <student><name>Ava</name></student>
3. Which format uses opening and closing tags to wrap each value?
A JSON
B XML
4. Which format can carry attributes, like <item id="7">?
A XML
B JSON
5. Which statement is correct?
A Both JSON and XML are self-describing text formats
B Only XML is self-describing; JSON is not

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} AXML: opening and closing tags, with an attribute carrying extra information
2<student year="12"><name>Ava</name></student> B<xs:element name="age" type="xs:integer"/>
3Both JSON and XML are self-describing: the field names travel with the data CJSON: compact key-value pairs in braces, short and easy to read
4XML can be checked against a schema, so the receiver can confirm the structure is valid D{"city": "Brisbane"} and <city>Brisbane</city>
5<name>Ava</nme> EThe closing tag does not match the opening tag. XML needs every element closed with a matching tag.
6{name: 'Ava', year: 12,} FJSON keys and strings need double quotes, and a trailing comma is not allowed.

Definitions

JSON vs XML

Fill in the Blanks

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

1.
<name>Ava</____>
2.
{"name"_ "Ava", "year": 12}
3.
<?xml _______="1.0"?>
4.
{"marks": _88, 74, 91]}
5.
<xs:element name="age" ____="xs:integer"/>

Spot the Error

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

Question 1
A {'name': 'Ava',
B "year": 12,
C "active": true}
Question 2
A <student>
B <name>Ava</nam>
C <year>12</year>
D </student>
Question 3
A {
B "name": "Ava"
C "year": 12
D }
Question 4
A <book id="7">
B <title>Dune</title>
C <cost cur=AUD>12</cost>
D </book>
Question 5
A import json
B text = '{"id": 7}'
C data = json.loads(text)
D print(data.id)

Answer Key

Comparing JSON and XML
Section A: Quick Questions
Q1
B — JSON
Q2
A — {"name": "Ava", "year": 12}
Q3
B — XML
Q4
A — XML
Q5
A — Both JSON and XML are self-describing text formats
Section B: Match the Pairs
Q1
{"name": "Ava", "year": 12} → JSON: compact key-value pairs in braces, short and easy to read
Q2
<student year="12"><name>Ava</name></student> → XML: opening and closing tags, with an attribute carrying extra information
Q3
Both JSON and XML are self-describing: the field names travel with the data → {"city": "Brisbane"} and <city>Brisbane</city>
Q4
XML can be checked against a schema, so the receiver can confirm the structure is valid → <xs:element name="age" type="xs:integer"/>
Q5
<name>Ava</nme> → The closing tag does not match the opening tag. XML needs every element closed with a matching tag.
Q6
{name: 'Ava', year: 12,} → JSON keys and strings need double quotes, and a trailing comma is not allowed.
Section C: Definitions
Q1
JSON vs XML — JSON is shorter and easier to read. XML uses tags and can carry attributes and schemas. Both are self-describing text formats for exchanging data between systems.
Section D: Fill in the Blanks
Q1
<name>Ava</name>
Q2
{"name": "Ava", "year": 12}
Q3
<?xml version="1.0"?>
Q4
{"marks": [88, 74, 91]}
Q5
<xs:element name="age" type="xs:integer"/>
Section E: Spot the Error
Q1
A — JSON keys and strings must use double quotes, not single quotes. The line should be {"name": "Ava",
Q2
B — Every XML opening tag needs a matching closing tag. The closing tag must be </name>, not </nam>.
Q3
B — JSON separates key-value pairs with commas. This line is missing the comma after "Ava" and should be "name": "Ava",
Q4
C — XML attribute values must be inside quotes. Attributes are something JSON does not have, and the line should be <cost cur="AUD">12</cost>.
Q5
D — json.loads() returns a Python dictionary, so you read a value with square brackets and the key name: data["id"]. Dot notation does not work on a dictionary.