简体   繁体   English

AWS IOT 核心规则在 DynamoDB 中错误的 JSON 格式

[英]AWS IOT Core Rule wrong JSON formatting in DynamoDB

I am using AWS IOT Core to store incoming data in a DynamoDB table.我正在使用 AWS IOT Core 将传入数据存储在 DynamoDB 表中。 The message payload looks like this:消息负载如下所示:

{
  "temperature": "8",
  "humidity": "80"
}

The Rule Query:规则查询:

SELECT temperature, humidity FROM '+/pub'

And the resulting entry in the DynamoDB table:以及 DynamoDB 表中的结果条目:

{"temperature":{"N":"26"},"humidity":{"N":"34.20000076"}}

What I expected:我期望的是:

{"temperature":"26","humidity": "34.20000076"}

I understand that these additional keys are value type identifiers but I do not see why I would need them and how they got there.我知道这些额外的键是值类型标识符,但我不明白为什么我需要它们以及它们是如何到达那里的。

DynamoDB does not persist data in native JSON but with DynamoDB-JSON, which is why you see the identifiers when you read back the data. DynamoDB 不会将数据保存在原生 JSON 中,而是使用 DynamoDB-JSON,这就是您在回读数据时看到标识符的原因。

I'm not sure on the IOT Core implementation but if you're using the DynamoDB SDK you can avoid those values by using a higher level client such as Document Client for JS.我不确定 IOT Core 实现,但如果您使用的是 DynamoDB SDK,则可以通过使用更高级别的客户端(例如 Document Client for JS)来避免这些值。 You can also use the built in converter's unmarshall the data to native JSON.您还可以使用内置转换器将数据解组为本机 JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM