Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
How do I extract Map type-attributes from DynamoDB item using .NET

I have successfully queried a DynamoDB dataset and returned the last item associated with the primary key. The item data consists of the following:

`{
 "machineID": {
  "N": "1322"
 },
 "ts": {
  "N": "1646299793339"
 },
 "data": {
  "M": {
   "average-speed": {
    "N": "0"
   },
   "in-machine-mode": {
    "N": "0"
   },
   "run-speed": {
    "N": "40"
   },
   "total-packs-life": {
    "N": "0"
   },
   "recipe-loaded-id": {
    "N": "1"
   },
   "total-packs-shift": {
    "N": "0"
   },
   "message-banner": {
    "N": "0"
   },
   "ts": {
    "N": "1646299793339"
   }
  }
 }
}`

I want to extract the Map values in JSON format but cannot find any instruction/tutorials on how this is achieved.

Here is the basic code to query and extract the last record relating to a machine number.

`var response = await client.QueryAsync(request);
    
    var result = response.Items;
    
    foreach(Dictionary<string, AttributeValue> item in result)
    {
        foreach(KeyValuePair<string, AttributeValue> kvp in item )
        {
            var attribute = kvp.Key;
            var value = kvp.Value;
            
            Console.WriteLine(attribute + " " + (value.N == null ? "" : value.N));              
        }
    }`

Output is as follows: ts 1646299793339 machineID 1322 data

How do I get the M attribute? I would appreciate help to resolve my understanding.

See above for trials

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Having spent some time searching for an answer, and in the process learning more about how dyanamoDB works, I now have a solution which works.

Essential I needed to convert the attribute key-value pair from the query into a document.

Achieved using:

    var response = await dynamoDBClient.QueryAsync(request);
    var attributes = response.Items.FirstOrDefault();
    var doc = Document.FromAttributeMap(attributes);

From this its a simple case of converting doc to a JSON Object

    Console.WriteLine(doc.ToJson());

Maybe there is another way? Comments appreciated.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda