Ask coding questions

← Back to all posts
Format json using JsonResponse (django)
h
ch1ck3n (2042)

Let's say i have a dict like this:

facts = {"doge": "awesome", "ch1ck3n": "awesome"}

and I use JsonResponse to make a API type thing.

return JsonResponse(facts) and it returns the json, except that it isn't formatted. I'm pretty sure there is a way but I'm not sure how to do it.

i want it to return the formatted JSON like

{
  "doge": "awesome",
  "ch1ck3n": "awesome"
}
Answered by Coder100 (18101) [earned 5 cycles]
View Answer
Comments
hotnewtop
ch1ck3n (2042)

actually i got it

json_dumps_params={'indent': 2}