Reputation: 501
I have a 3d dictionary and want to insert the data into sqlite3
I know how to insert 1d data but I haven't tried to insert 2d or 3d data and I don't know how to do it.
data = {'username': {'classes': {'closedclasses': {'classCode5': {'code': 'phys111',
'term': 'fall'}},
'openclasses': {'classCode1': {'code': 'art123',
'term': 'Fall'},
'classCode2': {'code': 'art111',
'term': 'spring'}}},
'name': {'firstName': 'aaaa', 'lastName': 'bbbb'}}}
The data will have more than one username and each username has a different amount of data for openclasses and closeedclasses. How can I store all the data so that in the future I can call them like this:
data[username]["openclasses"]["classCode2"]["code"]
data[username]["name"]["firstName"]
Upvotes: 0
Views: 98
Reputation: 53734
A possibility is to have table name users as follows
id
first_name
last_name
Then a table for classes
id
class_code
term
status # open or closed
As already mentioned in the comments, your json isn't really well structured. classCode5
, classCode2
etc should really only be classCode
whatever code you write you are going to have your work cut out fetching this information from the JSON.
Last but not least, you need a table to link the users and the classes.
id
user_id
class_id
Upvotes: 1