I have been trying to create multiple tables in a table using TinyDB. Here is a website to help you understand what TinyDb is (TinyDB PDF). The PDF file did not show how to insert multiple tables into one, one multiple data into one table.
I intended the json file to look like this:
"MASTER TABLE":
{
{"TABLE 1": {"1": {"Name": "Alice", "Age": 19}}
{"TABLE 2": {"1": {"Name": "John", "Age": 12}},
}
However, the issue is that I'm not sure how to insert Table1 and Table2 into the Master file table. SO it gave me the error that table1 is not an element. I know it isn't an element but I don't have any idea of how to fix it, to put the two tables under the Master file table. I'd appreciate any help.
Here's my codes:
from tinydb import TinyDB, Query
from tinydb import TinyDB, where
import json
with open("/home/pi/Desktop/jsontest/test.json", 'w+'):
table1 = TinyDB('/home/pi/Desktop/jsontest/test.json')
table1 = table1.table('TABLE 1')
table1.insert_multiple([{'Name' : 'Alice' , 'Age' : 19}])
table2 = TinyDB('/home/pi/Desktop/jsontest/test.json')
table2 = table2.table('TABLE 2')
table2.insert_multiple([{'Name' : 'john' , 'Age' : 12}])
overall = TinyDB('/home/pi/Desktop/jsontest/test.json')
overall = overall.table('MASTER TABLE')
overall.insert([table1])