Skip to content

Commit b4bbd5f

Browse files
authored
Update README.md
1 parent 0389b22 commit b4bbd5f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

.learn/exercises/05-returning-json/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
REST APIs have to return data in JSON format, not HTML format.
44

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:
66

77
```python
8+
# Add the jsonify method to your Flask import
9+
from flask import Flask, jsonify
810

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
13-
some_data = { "name": "Bobby", "lastname": "Rixer" }
11+
# Suppose you have your data in the variable named some_data
12+
some_data = { "name": "Bobby", "lastname": "Rixer" }
1413

1514
@app.route('/myroute', methods=['GET'])
1615
def hello_world():
17-
# you can convert that variable into a json string like this
16+
# You can convert that variable into a json string like this
1817
json_text = jsonify(some_data)
1918

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
2120
return json_text
2221
```
2322

@@ -30,12 +29,12 @@ todos = [
3029
]
3130
```
3231

33-
## 📝Instructions:
32+
## 📝 Instructions:
3433

3534
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:
3635

3736
```python
3837
[ { "label": "My first task", "done": False } ]
3938
```
4039

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

Comments
 (0)