June 2025
Beginner to intermediate
473 pages
13h 30m
English
Let’s say we have a file called employees.json, which is a JSON file with the following structure:
[ { "emp_no" : 10001 }, "birth_date" : "1953-09-02", "first_name" : "Georgi", 'last-name': "Facello", ... }, ... We need to form an XML file from the JSON file, and the XML file should look as follows:
<?xml version="1.0"?><employees> <employee no='10001' birth_date='1953-09-02'>Georgi Facello</employee> ...</employees>
This scenario is exactly the kind of task Python is designed for! The with keyword opens the source file and the target file. The code json.load reads the JSON file and turns it into a Python list of dictionaries (where each list entry is a dictionary with employee data). The ...
Read now
Unlock full access