Search code examples
javascriptnode.jsamazon-dynamodbunmarshalling

DynamoDB unmarshall only unmarshalling one Map when multiple exist


I am having trouble with unmarshalling information i'm retrieving from my DynamoDB table. This is t e raw format of it.

{
  "email": {"S": "[email protected]"},
  "name": {"S": "John Doe"},
  "clientConfiguration": {
    "M": {
      "chartTimeScale": {
        "S": "Periodic"
      },
      "naming": {
        "S": "Site"
      }
    }
  },
  "clientName": { "S": "Client" },
  "clientStatus": {"S": "Onboarding" },
  "createdDate": {"S": "2023-09-19T15:46:09.688Z"},
  "pageAccess": {
    "M": {
      "pageOne": {
        "BOOL": false
      },
      "pageTwo": {
        "BOOL": false
      },
      "pageThree": {
        "BOOL": false
      },
      "pageFour": {
        "BOOL": false
      },
      "pageFive": {
        "BOOL": false
      }
    }
  },
  "users": {
    "L": []
  }
}

When i run this through the unmarshall(data) I get the following:

{
    "email": "[email protected]",
    "name": "John Doe",
    "clientConfiguration": {
        "chartTimeScale": "Periodic",
        "naming": "Site"
    },
    "clientName": "Client" ,
    "clientStatus": "Onboarding" ,
    "createdDate": "2023-09-19T15:46:09.688Z",
    "pageAccess": {
        "M": {
            "Lifts": {
                "BOOL": true
            },
            "Roofs": {
                "BOOL": true
            },
            "HVAC": {
                "BOOL": true
            },
            "Refrigeration": {
                "BOOL": true
            },
            "Car Parks": {
                "BOOL": true
            }
        }
    },
    "users": []
}

I've tried using the unmarshall tool and creating my own version. but no luck.

Does anyone have any idea why and if so how to solve this. I'm using NodeJs


Solution

  • Easiest way to solve this issue is to use the Document Client, which abstracts you from the type descriptors that DynamoDB uses completely.

    You can learn more from this blog:

    https://aws.amazon.com/blogs/database/exploring-amazon-dynamodb-sdk-clients/

    As you show two completely different items it's hard to tell what the issue is, but my assumption is that you've double marshalled the item while saving it.