

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: JSON Syntax
incomplete
2: JSON Review
incomplete
3: Sending JSON
incomplete
4: Parsing JSON
incomplete
5: XML
incomplete
6: Why Use XML?
incomplete
This lesson's interactive features are locked, please to keep using them
JSON isn't just something we get from the server, we can also send JSON data!
In Python, we use the json module which provides two main methods: json.loads() and json.dumps().
json.dumps() is particularly useful for sending JSON.
As you may expect the JSON dumps() function does the opposite of loads. It takes a Python dictionary or list as input and converts it into a string. This is useful when we need to serialize the objects into strings to send them to our server or store them in a database.
import json
data: dict[str, str | bool] = {"name": "waseem", "chad": True}
json_string = json.dumps(data)
print(json_string) # {"name": "waseem", "chad": true}
# only the boolean changed!
Users need to be able to mark their projects as completed. However, update_project_by_id(project_id: str, project_obj: Project) -> Project is passing an invalid value to pyfetch, causing an error.
The body parameter in pyfetch expects a string when sending JSON data. You need to convert the Python dictionary to a JSON string before sending it.
Fix the code by converting the project_obj dictionary to a JSON string using json.dumps().