I'm querying an API that interfaces to MariaDB and this is how I get the data back.
{'TestTable': {'columns': ['Name', 'Id'], 'records': [['Jack', 1], ['Jill', 2]]}}
What I'm trying to achieve is to print the columns before the records like so:
Name: Jack
Id: 1
Name: Jill
Id: 2
I tried to take the data and put the columns and records into different lists and then my idea was to use an if to match the indexes and if match to print the to the format above, but it was the wrong index. Unfortuantely after trying to get it to work after about 5 different ways and 3 hours, I realized I had absolutely no idea what I was doing:
jsonData = json.loads(reqGet.text)
columns = jsonData['TestTable']['columns']
records = jsonData['TestTable']['records']
for idx, val in enumerate(records):
print(idx, val)
Output:
0 ['Jack', 1]
1 ['Jill', 2]
Any thoughts besides "Have you considered digging ditches?", would be great.