适用于 JavaScript 版本 3 (V3) 的 AWS 开发工具包提供了可靠地编组和解组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' }
}