As a string convert to json (Python )?

There is a piece of code where a function returns a string return str(blog_post.get_response(query))

C Python has faced for the first time and ask for help. I have to give this string into json format, how to do it? It is a framework flask.
June 14th 19 at 18:19
2 answers
June 14th 19 at 18:23
June 14th 19 at 18:21
Solution
you can create a dictionary with data and then create json
import json


data = {
 'users': [
{
 'id': 1,
 'name': 'user1',
},
{
 'id': 2,
 'name': 'user2',
},
],
}

json_str = json.dumps(data)

In a variable will lie json_str json string like this:
{"users": [{"id": 1, "name": "user1"}, {"id": 2, "name": "user2"}]}

Find more questions by tags Python