在DynamoDB Python(py)中插入多个json数据

2021-03-02 16:17:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有10k个json文件,我想把它们一个一个地插入Dynamo DB我想得到一些帮助。Python(py)

In all the json files the data are stored in the same format:

{
"_id": {
    "$oid": "582ff456aeddbf0ddcae6f58"
},
"product_filter": {
    "_id": {
        "Data_gender": "Women",
        ...
        ...
    }
},
"Data": {
    "AddDate": 1476546994,
    "fashionType": "Core",
    "Date": 123320000,
    "year": "2016",
    "brandDetailsEntry": {
        "id": 6746,
        "name": "lov me Weaves"
    },
    "id": 13132337,
    }
1条回答
网友
1楼 ·

这是我正在使用的代码示例

import boto3
import json
import decimal

dynamodb = boto3.resource('dynamodb')

table = dynamodb.Table('tshirts')
i=1
while i<20020:
    with open("data"+str(i)+".json") as json_file:
    x=json.load(json_file, parse_float = decimal.Decimal)
    # for j in x:
    #     product_filter = j['product_filter']
   print(x)
   data = table.put_item(
       Item={'product_filter': x})
   data.save()
   print i
i+=1

i named my json files from 1 to 2000**

相关问题