

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 (JavaScript Object Notation), is a standard for representing structured data based on JavaScript's object syntax. It is commonly used to transmit data in web apps via HTTP. For example, the HTTP pyfetch() requests we have been using in this course have been returning Jello projects, users, and issues as JSON.
JSON supports the following primitive data types:
"Hello, World!"42 or 3.14truenullAnd the following collection types:
[1, 2, 3]{"key": "value"}JSON looks a lot like Python dictionaries and lists. The following is valid JSON data:
{
"movies": [
{
"id": 1,
"genre": "Action",
"title": "Iron Man",
"director": "Jon Favreau"
},
{
"id": 2,
"genre": "Action",
"title": "The Avengers",
"director": "Joss Whedon"
}
]
}
Python provides us with tools to help us work with JSON. After making an HTTP request with pyfetch(), we get a response object. That response object offers us methods that help us interact with the response. One such method is the .json() method. The .json() method takes the response stream returned by a pyfetch request and returns an awaitable that resolves into a Python object (dictionaries and lists) parsed from the JSON body of the HTTP response!
resp = await pyfetch(...)
python_object_response = await resp.json()
Our get_projects function is almost done, we just need to parse the response data as JSON and return it.
The result of this method is not JSON. It is the result of taking JSON data from the HTTP response body and parsing that input into a Python object.