Iterating through a class to retrieve json response – Synapse/Django

Question:

I have a django project and I am trying to integrate SynapsePay Api. I sent a request that returned a class as a response. I am trying to figure out how to cycle or parse the response to get to the json so that I can grab certain values from the response that was returned. I have looked everywhere and cant seem to find a solution or a way to get into a class objects and reach the json part of the return.

Here is the response that I am getting…

I want to grab the _id from both of the objects returned in the object response below. Does anyone know how I can do this??

[  
   <class 'synapse_pay_rest.models.nodes.ach_us_node.AchUsNode'>(   {  
      'user':"<class 'synapse_pay_rest.models.users.user.User'>(id=...49c04e1)",
      'json':{}
   }   )
]
Asked By: Omar Jandali

||

Answers:

It would help if you linked the library you are using, which I’m guessing is
https://github.com/SynapseFI/SynapseFI-Python

In this case, there really is no need to grab the JSON – the client library has already wrapped the returned JSON in easy to use objects. The class instances (not classes) it returns already have an id attribute which is what you want. You can also get the raw JSON from the json attribute (based on my reading of the source code.

I’d recommend installing IPython (pip install ipython) and using the repl to execute commands and play around with the response objects. You will quickly be able to use tab completion to find what attributes are available.

Answered By: spookylukey