如何将 DynamoDB JSON 转换为常规 Javascript 对象
如何将 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"
}
How can I convert a DynamoDB JSON object to a regular object in JavaScript?
Example DynamoDB object:
{
"key1": {
"S": "val1"
},
"key2": {
"S": "val2"
},
"key3": {
"M": {
"key4": {
"M": {
"key5": {
"S": "val5"
}
}
}
}
},
"key6": {
"S": "val6"
}
}
Expected output:
{
"key1": "val1",
"key2": "val2",
"key3": {
"key4": {
"key5": "val5"
}
},
"key6": "val6"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
unmarshall
@aws-sdk/util-dynamodb
库 中的函数。You can use the
unmarshall
function in the@aws-sdk/util-dynamodb
library.我在这里找到了类似的解决方案:
https://github.com/dangerfarms/unmarshall-dynamodb-json
https://dangerfarms.github.io/unmarshall-dynamodb-json/
解组行如下所示:
I found a similar solution here:
https://github.com/dangerfarms/unmarshall-dynamodb-json
https://dangerfarms.github.io/unmarshall-dynamodb-json/
The unmarshalling line looks like this: