如何在dynamodb中插入json

这是我的代码。
我想将asset_data json插入到asset_data列中。 我正在使用aws sdk。 它说aws sdk现在支持json。 http://aws.amazon.com/releasenotes/SDK/JavaScript/1691866671551861

 var asset_data = { "name": "name" + i, "contentUrl": "http://www.hdwallpapersimages.com/nature-beauty-desktop-images/94892/", "size": 300, "headline": "headline", "description": "assetUrl reference for the creator", "encodingFormat": 'jpeg' }; var params = { TableName: 'xyz', Item: { // a map of attribute name to AttributeValue "asset_id": {S: "asset" + i}, "hit_id": {S: "0"}, "created_date": {"S": Date.now().toString()}, "status": {N: "0"}, "operation": {S: "image_tagging"}, "asset_data": {L: asset_data}, "source": {S: "DAM"}, "completed_date": {S: Date.now().toString()}, "response_data": {S: "taged value"} // more attributes... }, ReturnValues: 'NONE', // optional (NONE | ALL_OLD) ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES) ReturnItemCollectionMetrics: 'NONE' // optional (NONE | SIZE) }; db.putItem(params, function (err, data) { if (err) console.log(err); // an error occurred else console.log("inserted..."); // successful response }); 

您可以使用DynamoDB Document Client SDK:

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property

文档客户端通过抽象化属性值的概念简化了对Amazon DynamoDB中的项目的处理。 这个抽象注释了作为input参数提供的本地JavaScripttypes,以及将注释的响应数据转换为本机JavaScripttypes。

为了您的具体情况,请查看从正式文档中提取的以下示例中Map属性值(M)作为MapAttribute传递。 Document Client API负责在Javascript和DynamoDBtypes之间进行适当的编组/解组(这意味着您不必在使用非必需时指定Attribute Values (S,N,L,...)基于文档的SDK):

 var params = { TableName = 'Table', Item: { HashKey: 'haskey', NumAttribute: 1, BoolAttribute: true, ListAttribute: [1, 'two', false], MapAttribute: { foo: 'bar'}, NullAttribute: null } }; var docClient = new AWS.DynamoDB.DocumentClient(); docClient.put(params, function(err, data) { if (err) console.log(err); else console.log(data); });