JsonPath检查AWS SNS发送的消息中的值

时间:2014-11-10 13:11:17

标签: json apache-camel jsonpath

我正在尝试检查亚马逊通知发送的 notificationType 。 我想检查这种类型是否为“交付”,以便我可以使用驼峰将其路由到不同的位置。

我最初的尝试是 $。消息[?(@ notificationType ='Delivery')] 但我收到错误无法应用于JSON对象只有JSON数组

我一直在网上尝试各种方式http://ashphy.com/JSONPathOnlineEvaluator,但我似乎无法提取该值或进行检查。

{
  "Type": "Notification",
  "MessageId": "defg",
  "TopicArn": "arn:email",
  "Message": "{\"notificationType\":\"Delivery\",\"mail\":{\"timestamp\":\"2014-11-10T12:46:52.599Z\",\"source\":\"example@example.com\",\"messageId\":\"000001499000000\",\"destination\":[\"example@example.com\"]},\"delivery\":{\"timestamp\":\"2014-11-10T12:46:53.949Z\",\"processingTimeMillis\":1350,\"recipients\":[\"example@example.com\"],\"smtpResponse\":\"250 2.0.0 OK 1415623613 u3si30734178qat.92 - gsmtp\",\"reportingMTA\":\"abc\"}}",
  "Timestamp": "2014-11-10T12:46:54.003Z",
  "SignatureVersion": "1",
  "Signature": "sXkzkMQGawqJCibQ==",
  "SigningCertURL": "https:xyz",
  "UnsubscribeURL": "https:zyx"
}

编辑1 我刚刚注意到,所有在线解析似乎都无法正常工作。即使这些例子也不适用于它们

2 个答案:

答案 0 :(得分:1)

我认为SNS可以将值放在标题中。 如果是这样,您可以根据标头中的匹配属性进行路由。

答案 1 :(得分:0)

问题是从Amazon返回的Message Json是对Strings的转义。

杰克逊用转义的字符串解析上面的内容,但JsonPath不会。
如果您将Json更改为以下命令,则可以使用。

  

$。消息[?(@。notificationType =='Delivery')]

[
   {
      "notificationType" : "Delivery",
      "mail" : {
         "timestamp" : "2014-11-10T12: 46: 52.599Z",
         "source" : "example@example.com",
         "messageId" : "000001499000000",
         "destination" : [
            "example@example.com"
         ]
      },
      "delivery" : {
         "timestamp" : "2014-11-10T12: 46: 53.949Z",
         "processingTimeMillis" : 1350,
         "recipients" : [
            "example@example.com"
         ],
         "smtpResponse" : "2502.0.0OK1415623613u3si30734178qat.92-gsmtp",
         "reportingMTA" : "abc"
      }
   }
]