Unmarshall DynamoDB JSON

问题描述:

鉴于一些DynamoDB JSON通过DynamoDB NewImage流事件,我该如何将它解组到常规JSONUnmarshall DynamoDB JSON

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

通常我会用AWS.DynamoDB.DocumentClient,但我似乎无法找到一个通用的马歇尔/和解组功能。

旁注:我是否会丢失任何反编组DynamoDB JSON到JSON并返回?

+0

如果其他人来寻找这个问题的蟒蛇/博托版本,这里是相关的问题:https://*.com/questions/36558646/how-to-convert-from-dynamodb-wire-protocol-to- native-python-object-manually- – VillasV

您可以使用AWS.DynamoDB.Converter.unmarshall函数。调用下面将返回{ updated_at: 146548182, uuid: 'foo', status: 'new' }:可在DynamoDB的编组JSON格式进行建模

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

一切都可以安全地转换为从JS对象。

+0

ARGH ..多么糟糕的API,它需要的东西'aws.DynamoDB.Converter.output({'M':record.dynamodb.NewImage})' – hendry

+0

'AWS.DynamoDB .Converter.output'是将[DynamoDB AttributeValue](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html)对象转换为JSON样式对象的DocumentClient的一部分。我认为'M'是你在流事件中获得的数据的一部分。 – giaour

+1

我打开了一个PR,通过添加不需要'M'键的'marshall'函数来改进API,并且它包含在SDK的2.71.0版本中。 – giaour