Reputation: 1
How to insert data in to datastore? The data could be like the one below:
{
'food': [{
"item_name": item,
'price': price
}, {
"item_name": item,
'price': price
}],
'beverages': [{
''
'beverage_name': beverage,
'beverage_price': b_price
}, {
''
'beverage_name': beverage,
'beverage_price': b_price
}]
}
Upvotes: 0
Views: 818
Reputation: 2805
The data that you are trying to add to the Google Cloud Datastore
is a JSON
string. The way you have it in your question is wrong structured. The proper JSON
example would be:
{
"food": [
{ "food_name":"NAME1", "food_price":"PRICE1" },
{ "food_name":"NAME2", "food_price":"PRICE2" },
{ "food_name":"NAME3", "food_price":"PRICE3" }
],
"beverages":[
{ "beverage_name":"NAME1", "beverage_price":"PRICE1" },
{ "beverage_name":"NAME2", "beverage_price":"PRICE2" }
]
}
To add the data from the JSON string to the Datastore you have to:
food
for the Kind
value in Datastoreentity
to add the data to the Datastorebeverages
for the Kind
value in Datastoreentity
to add the data to the DatastoreFor further information, you can refer to Google Cloud Data Store Entities, Properties, and Keys documentation.
I have done a little bit coding myself and here is my code example in GitHub for Python. You can take the idea of how it works and test it. It will create two different Kind
values in Datastore and add the food data in foods
and beverage data to beverages
.
Upvotes: 1