如何将 DynamoDB JSON 对象转换为 JavaScript 中的常规对象?
示例 DynamoDB 对象:
{
"key1": {
"S": "val1"
},
"key2": {
"S": "val2"
},
"key3": {
"M": {
"key4": {
"M": {
"key5": {
"S": "val5"
}
}
}
}
},
"key6": {
"S": "val6"
}
}
预期输出:
{
"key1": "val1",
"key2": "val2",
"key3": {
"key4": {
"key5": "val5"
}
},
"key6": "val6"
}
最佳答案
您可以使用 unmarshall
function in the @aws-sdk/util-dynamodb
library .
const { unmarshall } = require("@aws-sdk/util-dynamodb");
const regularObject = unmarshall(dynamoObject);
console.log(regularObject); // Will output converted object
https://stackoverflow.com/questions/71289799/