Unmarshall DynamoDB JSON

夙愿已清 提交于 2020-05-14 17:53:06

问题


Given some DynamoDB JSON via a DynamoDB NewImage stream event, how do I unmarshall it to regular JSON?

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

Normally I would use AWS.DynamoDB.DocumentClient, however I can't seem to find a generic Marshall/Unmarshall function.

Sidenote: Do I lose anything unmarshalling DynamoDB JSON to JSON and back again?


回答1:


You can use the AWS.DynamoDB.Converter.unmarshall function. Calling the following will return { updated_at: 146548182, uuid: 'foo', status: 'new' }:

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

Everything that can be modeled in DynamoDB's marshalled JSON format can be safely translated to and from JS objects.



来源:https://stackoverflow.com/questions/44535445/unmarshall-dynamodb-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!