I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and successfully sends a request to an api, and receives a good response back. I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in addition to sending the raw response data back in an HttpResponse I would also like to strip out some of the data and create a summary report of it, to also send back in my HttpResponse.
I can see the good response data from the request in my command prompt window, and it contains a list of items inside of the object to which I've assigned the response data. So my question is how do I get at the list of items that has been returned back to me as well as all of the data (key/value pairs) contained in each list item?
I'm sure there must be some kind of conversion process that I have to run the raw response data through. I just haven't out what it is yet.
I've never tried to do this before, from within a django view. If I were trying to do this on the client side I would use something like this:
mydata = jQuery.parseJSON(data);
to make the data accessible, but never having done anything like this before on the server side I haven't found anything yet that's been useful or has worked.
I would appreciate any help anyone can offer, while I continue to search for an answer.
Thanks.
I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and successfully sends a request to an api, and receives a good response back. I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in addition to sending the raw response data back in an HttpResponse I would also like to strip out some of the data and create a summary report of it, to also send back in my HttpResponse.
Scot, Thanks for the reply. OK I've gotten down to the point to where I have my version of your json_data in your code below, but I'm not sure I understand exactly what your code is doing, after you have the json_data variable contents. In my case the first object of response data that I'm trying to use is a list of two items, with each item containing multiple keys and internal or sub objects within them.
I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and successfully sends a request to an api, and receives a good response back. I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in addition to sending the raw response data back in an HttpResponse I would also like to strip out some of the data and create a summary report of it, to also send back in my HttpResponse.