your programing

Unmarshall DynamoDB JSON

lovepro 2023. 3. 13. 23:27
반응형

Unmarshall DynamoDB JSON

DynamoDB를 통해 일부 DynamoDB JSON을 지정NewImage스트리밍 이벤트, 일반 JSON으로 마킹 해제하려면 어떻게 해야 하나요?

{"updated_at":{"N":"146548182"},"uuid":{"S":"foo"},"status":{"S":"new"}}

평소에는 AWS를 사용합니다.Dynamo DB.Document Client는 일반적인 Marshall/Unmarshall 함수를 찾을 수 없습니다.

사이드노트:DynamoDB JSON을 JSON에게 넘겼다가 다시 돌려주는 것을 잃어버렸습니까?

를 사용할 수 있습니다.AWS.DynamoDB.Converter.unmarshall기능.다음을 호출하면 되돌아갑니다.{ updated_at: 146548182, uuid: 'foo', status: 'new' }:

AWS.DynamoDB.Converter.unmarshall({
    "updated_at":{"N":"146548182"},
    "uuid":{"S":"foo"},
    "status":{"S":"new"}
})

DynamoDB의 Marshalled JSON 형식으로 모델링할 수 있는 모든 것은 JS 객체 간에 안전하게 번역할 수 있습니다.

AWS SDK for JavaScript 버전 3(V3)은 DynamoDB 레코드를 안정적으로 마셜링 및 마셜링 해제하기 위한 좋은 방법을 제공합니다.

const { marshall, unmarshall } = require("@aws-sdk/util-dynamodb");

const dynamo_json = { "updated_at": { "N": "146548182" }, "uuid": { "S": "foo" }, "status": { "S": "new" } };

const to_regular_json = unmarshall(dynamo_json);

const back_to_dynamo_json = marshall(to_regular_json);

출력:

// dynamo_json    
{ 
      updated_at: { N: '146548182' },
      uuid: { S: 'foo' },
      status: { S: 'new' }
}

// to_regular_json
{ updated_at: 146548182, uuid: 'foo', status: 'new' }

// back_to_dynamo_json
{
   updated_at: { N: '146548182' },
   uuid: { S: 'foo' },
   status: { S: 'new' }
}

언급URL : https://stackoverflow.com/questions/44535445/unmarshall-dynamodb-json

반응형