I have code that is selecting some data from my database.
It returns a list:
selects = [(2, '4'), (2, '17'), (3, '65'), (1, '54'), (2, '14'),...]
I want to transform this list into a JSON object, so I do:
selects = json.dumps(selects)
Giving me a value like this:
[[2, "4"], [2, "17"], [3, "65"], [1, "54"], [2, "14"], ...]
After that, I want to write a for loop to get each object of the dictionary and save into a var. For example:
[[2, "4"]]
var1 = 2
var2 = "4"
But I'm having a problem with extracting the value that I want. When I try var = json[0], it only returns the [.
My idea is to make a for to run thought all the objects in the json, saving them into a var, and sending to another process...
What should I do to save the values like the example above?
Here is the code that I'm using:
import json
class Pull():
def process(self, **kwargs):
data = kwargs.get('data')
client = kwargs.get('client')
postgres = kwargs.get('postgres')
selects = postgres.select(data_type='session')
selects = json.dumps(selects)
for select in selects:
var1 = select[0]
var2 = select[1]
sessions = client.get_sessions(city=var1, cinema=var2)