Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda