You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .learn/exercises/05-returning-json/README.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,21 @@
2
2
3
3
REST APIs have to return data in JSON format, not HTML format.
4
4
5
-
You can use the [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data like this:
5
+
You can use the [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data, like this:
6
6
7
7
```python
8
+
# Add the jsonify method to your Flask import
9
+
from flask import Flask, jsonify
8
10
9
-
# add the jsonify method to your Flask import
10
-
from flask import Flask, jsonify
11
-
12
-
# suppose you have your data in the variable named some_data
#you can convert that variable into a json string like this
16
+
#You can convert that variable into a json string like this
18
17
json_text = jsonify(some_data)
19
18
20
-
#and then you can return it to the front end in the response body like this
19
+
#And then you can return it to the front end in the response body like this
21
20
return json_text
22
21
```
23
22
@@ -30,12 +29,12 @@ todos = [
30
29
]
31
30
```
32
31
33
-
## 📝Instructions:
32
+
## 📝Instructions:
34
33
35
34
1. Create a global variable called `todos`. Do not declare the variable inside any function. Declare the variable in the global scope and make sure the variable contains at least one task item (our task objects) inside with the following structure:
36
35
37
36
```python
38
37
[ { "label": "My first task", "done": False } ]
39
38
```
40
39
41
-
2.Change the function on the GET method's endpoint from string output so that it will return the jsonified version of the global variable `todos`.
40
+
2. Change the function on the GET method's endpoint from string output so that it will return the jsonified version of the global variable `todos`.
0 commit comments