Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

populate json to html with django template

In order to better debug my api, I would like to create a debug page which shows all details of the response json obj line by line. I think it can be done by code or django template. What is the simplest way to do it?

https://developers.facebook.com/tools/explorer/?method=GET For example, facebook explorer does list details of the response json obj like this.

{
  "id": "xxx", 
  "name": "xxx", 
  "first_name": "xxx", 
  "last_name": "xxx", 
  "link": "xxx", 
  "username": "xxx", 
  "hometown": {
    "id": "xxx", 
    "name": "xxx"
  }, 
  "location": {
    "id": "xxx", 
    "name": "xxx"
  }, 
  "bio": "Drink Coffee in Whitehorse", 

  "work": [
    {
      "employer": {
        "id": "xxx", 
        "name": "xxx"
      }, 
      "location": {
        "id": "xxx", 
        "name": "xxx"
      }, 
      "position": {
        "id": "xxx", 
        "name": "xxx"
      }, 
      "start_date": "2009-01", 
      "end_date": "0000-00"
    }, 
}
like image 786
lucemia Avatar asked Jan 27 '26 12:01

lucemia


1 Answers

You just need to call json.dumps() with the indent keyword argument equal to the number of spaces to indent the generated JSON by for pretty printing.

For example:

json.dumps(spam_and_eggs, indent=4)
like image 155
aviraldg Avatar answered Jan 29 '26 00:01

aviraldg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!