Dynamodb 查询返回带有语法错误的 json

问题描述 投票:0回答:1

使用 Nodejs 连接到 dynamoDb 表,我想从表中获取项目。我尝试使用查询选项,它返回带有项目的 json,但有时它返回带有语法错误的 Json

这是我的代码:

let ddb = new AWS.DynamoDB(config)
export const dynamoDb = ddb
export const dynamoClient = new AWS.DynamoDB.DocumentClient({
  service: dynamoDb
})

let params = {
    TableName: auditTable,
    IndexName: 'importId-auditStatus-index',
    KeyConditionExpression: 'importId = :importId and auditStatus = :auditStatus',
    ExpressionAttributeValues: {
      ':importId': importId,
      ':auditStatus' : 'Imported'
    }
  }

let response = await dynamoClient.query(params, function(err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      return data;
    }
  }).promise();
  console.log("response",response)

有时它会返回带有语法错误的 Json,如下所示

{
    "Count":117,
    "Items":[
        ... truncated by me ...
        {
            "pricingTemplate":{
                "NULL":true
            },
            "auditId":{
                "S":"7555555_15287101"
            },
            "importId":{
                "S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"
            },
            "auditStatus":{
                "S":"Imported"
            },
            "Id":{
                "S":"420f50cb-3d03-49cb-b1da-1a36aa099e6c"
            },
            "recordType":{
                "S":"currecy_test_tl"
            }
        }
,{"pricingTemplate":{"NULL":true},"auditId":{"S":"7555555_15287164"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"}7555555_15287206"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"},"Id":{"S":"e7042719-fa77-4939-9d05-ad41f3bdc7dc"},"recordType":{"S":"currecy_test_tl"}},{"pricingTemplate":{"NULL":true},"auditId":{"S":"7555555_15287155"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"},"Id":{"S":"bee5d2e3-60cf-4ecf-8249-d25de6e8c28a"},"recordType":{"S":"currecy_test_tl"}},
        {
            "pricingTemplate":{
                "NULL":true
            },
            "auditId":{
                "S":"7555555_15287111"
            },
            "importId":{
                "S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"
            },
            "auditStatus":{
                "S":"Imported"
            },
            "Id":{
                "S":"2161a17f-63c5-4c45-b7b4-9750cc202b23"
            },
            "recordType":{
                "S":"currecy_test_tl"
            }
        }
    ],
    "ScannedCount":117
}

编辑:

语法错误位于

auditStatus":{"S":"Imported"}7555555_15287206"},

node.js amazon-dynamodb dynamodb-queries
1个回答
0
投票

您共享的代码和您共享的输出不一致。您在代码中使用的文档客户端

dynamoClient
返回本机 JSON。代码中的低级客户端
dynamoDb
ddb
将返回 DynamoDB JSON,这就是您输出并调用语法错误的内容。

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypeDescriptors

© www.soinside.com 2019 - 2024. All rights reserved.