I'm fetching some data from an API on regular interval and wants to store the JSON data into database to access and use later.
From API, I get data in this sample each time:
'{"data": {"cursor": null, "files": {"nodes": [{u'code': u'BOPhmYQg5Vm', u'date': 1482244678,u'counts': 2, u'id': u'1409492981312099686'}, {u'code': u'g5VmBOPhmYQ', u'date': 1482244678,u'counts': 5, u'id': u'1209968614094929813'}]}}}'
I can json_data = json.loads(above_data)
and then fetch nodes
as nodes_data = json_data["data"]["files"]["nodes"]
which gives a list of nodes
.
I want to store this nodes
data into DB column data = Column(db.Text)
of Text
type. Each time there are going to be 10-15 values in nodes list.
How do I store? There are multiple nodes
and I need it in a way that in future I can append/add more nodes
to already available data
column in my db.
While I would like to do json.loads(db_data_col)
so that I get valid json and can loop over all of nodes
to get internal data and use later.
I'm confused on how to store in db and access later in valid json format.
Edit 1: Using Sqlite for testing. Can use PostgresSQL in future. Text
type of column is main point.