给定一些DynamoDB JSON通过DynamoDB NewImage流事件,如何将其解锁为常规JSON
{"updated_at":{"N":"146548182"},"uuid":{"S":"foo"},"status":{"S":"new"}}通常我会使用AWS.DynamoDB.DocumentClient,但是我似乎找不到一个通用的Marshall/Unmarshall函数。
Sidenote:我是否失去了将DynamoDB JSON解编组到JSON并再次返回的任何东西?
发布于 2017-06-14 06:01:33
您可以使用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的封送JSON格式建模的所有内容都可以安全地转换到JS对象和从JS对象。
发布于 2021-02-03 05:31:38
适用于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' }
}https://stackoverflow.com/questions/44535445
复制相似问题