← QCE Digital Solutions Unit 4

Comparing JSON and 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.

Understanding Comparing JSON and XML in QCE Digital Solutions Unit 4

What it does: Each format labels its value (city) inside the data itself, so a receiving system can read it without a separate description. An XML Schema (XSD) defines the allowed elements and data types, which is a feature of XML that plain JSON does not have built in. JSON uses curly braces and key: value pairs. The other snippet uses tags, which is XML. Attributes sit inside an XML opening tag. JSON has no attributes, only keys and values. JSON is short and easy to read, so it uses less bandwidth and is common in web APIs. XML is still used in some older or strictly structured systems.

Common mistakes: JSON keys and strings must use double quotes, not single quotes. The line should be {"name": "Ava",. Every XML opening tag needs a matching closing tag. The closing tag must be </name>, not </nam>.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 89–125) and word search (Modules 17–125).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which format is usually shorter for the same data?
JSONXML
Matches
<name>Ava</nme>
↓
The closing tag does not match the opening tag. XML needs every element closed with a matching tag.
Applying
Meanings
Term
JSON vs XML
Meaning
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.
Practice
import json
Testing
Gaps
<name>Ava</>
Check Answer
Spots
1{'name': 'Ava',
2 "year": 12,

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Meerkat' badge — Communicator, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which format is usually shorter for the same data?
A. XML
B. JSON ✓
XML repeats each name in an opening and closing tag, so the same data takes more characters. JSON uses key: value pairs with no closing names.
2. Which snippet is JSON?
A. {"name": "Ava", "year": 12} ✓
B. <student><name>Ava</name></student>
JSON uses curly braces and key: value pairs. The other snippet uses tags, which is XML.
3. Which format uses opening and closing tags to wrap each value?
A. JSON
B. XML ✓
XML wraps data in tags such as <name>Ava</name>. JSON does not use tags.
4. Which format can carry attributes, like <item id="7">?
A. XML ✓
B. JSON
Attributes sit inside an XML opening tag. JSON has no attributes, only keys and values.
5. Which statement is correct?
A. Both JSON and XML are self-describing text formats ✓
B. Only XML is self-describing; JSON is not
Both formats include names (keys or tags) that describe each value, so a reader can tell what the data means. Both are plain text.

Match the Pairs

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

Key Term

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.

Fill in the Blanks

1. <name>Ava</name>
Hint: Type the element name that must match the opening tag to close this XML element.
2. {"name": "Ava", "year": 12}
Hint: Type the single symbol JSON puts between a key and its value.
3. <?xml version="1.0"?>
Hint: Type the attribute name an XML declaration uses to state which XML release the file follows.
4. {"marks": [88, 74, 91]}
Hint: Type the opening bracket that starts a JSON list of values.
5. <xs:element name="age" type="xs:integer"/>
Hint: Type the attribute name an XML schema uses to say what kind of data an element must hold.

Spot the Error

Question 1
A {'name': 'Ava',
B "year": 12,
C "active": true}
Line A — JSON keys and strings must use double quotes, not single quotes. The line should be {"name": "Ava",
Question 2
A <student>
B <name>Ava</nam>
C <year>12</year>
D </student>
Line B — Every XML opening tag needs a matching closing tag. The closing tag must be </name>, not </nam>.
Question 3
A {
B "name": "Ava"
C "year": 12
D }
Line B — JSON separates key-value pairs with commas. This line is missing the comma after "Ava" and should be "name": "Ava",
Question 4
A <book id="7">
B <title>Dune</title>
C <cost cur=AUD>12</cost>
D </book>
Line 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>.
Question 5
A import json
B text = '{"id": 7}'
C data = json.loads(text)
D print(data.id)
Line 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.

Student with a class code? Join your class →