0.1.0 • Published 1 year ago

aws-dynamodb-marshaler v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

aws-dynamodb-marshaler

DynamoDB util to help format query response to json without the extra steps needed.

Raw response:

{
  "Items": [
    {
      "id": {
        "S": "0122asdfg1110001",
      },
      "name": {
        S: "meteor",
      },
      "createdDate": {
        "S": "2022-11-24T01:42:12.828Z",
      },
      "lastModifiedDate": {
        "S": "2022-11-24T01:42:12.828Z",
      },
      "product": {
        "S": "module",
      }
    }
  ],
}

After unmarshal:

[
    {
      "id": "0122asdfg1110001",
      "name": "meteor",
      "createdDate": "2022-11-24T01:42:12.828Z",
      "lastModifiedDate": "2022-11-24T01:42:12.828Z",
      "product": "module"
    }
]

Getting started

Install the package

npm install --save aws-dynamodb-marshaler

Import the library

import unmarshal from "aws-dynamodb-marshaler";

How to use it?

Just pass the value/response coming from the DynamoDB query into the util function and it will return the result back in JSON.

const dynamodbResponse = await dbc.query(dbQuery).promise();

// Clean JSON object
const jsonResult = unmarshal(dynamoddbResponse);

Note

The JSON response from unmarshal will only return the object within DynamoDB Items property