Creating JSON text with json.dumps
Turns a Python dictionary or list into JSON text (double-quoted keys, braces, square brackets) ready to send. json.loads() does the reverse and turns JSON text back into Python data.
Understanding Creating JSON text with json.dumps in QCE Digital Solutions Unit 4
What it does: A Python list passed to json.dumps() becomes a JSON array written in square brackets: [1, 2, 3]. JSON objects use braces around key-value pairs, and every key is wrapped in double quotes. json.dumps() returns a string, which is why it is ready to send in a request. Use json.loads() to get a dictionary back.
Common mistakes: Key-value pairs go inside braces { }, not square brackets. Square brackets are for arrays (lists) and cannot hold name: value pairs. It should be p = {"name": "Ava", "yr": 12}. json.dump() writes to a file and needs a file argument. To turn a list into a JSON string, use json.dumps() (with an s for string): text = json.dumps(scores).
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 334–401) and word search (Modules 127–401).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
json.dumps()Fill in the Blanks
Spot the Error
Student with a class code? Join your class →