Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am not sure I understand the purpose of the flask.jsonify method. I try to make a JSON string from this:

data = {"id": str(album.id), "title": album.title}

but what I get with json.dumps differs from what I get with flask.jsonify.

json.dumps(data): [{"id": "4ea856fd6506ae0db42702dd", "title": "Business"}] 

flask.jsonify(data): {"id":…, "title":…}

Obviously I need to get a result that looks more like what json.dumps returns. What am I doing wrong?

1 Answer

0 votes
by (106k points)

You can understand the difference between json.dumps vs flask.jsonify by seeing the below-mentioned lines of codes:-

flask.jsonify(**data)

or

flask.jsonify(id=str(album.id), title=album.title)

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 2, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Jul 2, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Jul 2, 2020 in Python by Sudhir_1997 (55.6k points)

Browse Categories

...