Looking at this example in the AWS DynamoDB documentation, I see that PutItemRequest.Item
is a Dictionary
. I'm trying to insert a complex JSON object into DynamoDB that can have anywhere between 200 to 300 attributes within a hierarchy of nested objects and arrays.
Do I really have to convert that JSON object to a Dictionary
before I can insert it into DynamoDB? If so, is there a way to do this that doesn't involve hardcoding and/or manually converting it one attribute at a time?
Apologies if this question is a little vague. I'm really just looking for pointers on how to proceed from here.
CodePudding user response:
The documentation includes an example of how to Insert JSON Format Data into a DynamoDB Table:
// using Amazon.DynamoDBv2;
// using Amazon.DynamoDBv2.DocumentModel;
var client = new AmazonDynamoDBClient();
var table = Table.LoadTable(client, "AnimalsInventory");
var jsonText = "{\"Id\":6,\"Type\":\"Bird\",\"Name\":\"Tweety\"}";
var item = Document.FromJson(jsonText);
table.PutItem(item);
More broadly, per the same documentation:
The AWS SDK for .NET supports JSON data when working with Amazon DynamoDB. This enables you to more easily get JSON-formatted data from, and insert JSON documents into, DynamoDB tables.