mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-29 08:42:28 +00:00
Add support for top-level JSON array in payload
Detect if leading character in JSON payload is an array bracket. If found, decode payload into an interface{} and then save the results into payload["root"]. References to payload values would need to reference the leading, "virtual" root node (i.e. "root.0.name"). Fixes #215
This commit is contained in:
parent
f692da2465
commit
0e90ccb441
5 changed files with 127 additions and 5 deletions
|
@ -425,6 +425,57 @@ Travis sends webhooks as `payload=<JSON_STRING>`, so the payload needs to be par
|
|||
]
|
||||
```
|
||||
|
||||
## JSON Array Payload
|
||||
|
||||
If the JSON payload is an array instead of an object, `webhook` will process the payload and place it into a "root" object.
|
||||
Therefore, references to payload values must begin with `root.`.
|
||||
|
||||
For example, given the following payload (taken from the Sendgrid Event Webhook documentation):
|
||||
```json
|
||||
[
|
||||
{
|
||||
"email": "example@test.com",
|
||||
"timestamp": 1513299569,
|
||||
"smtp-id": "<14c5d75ce93.dfd.64b469@ismtpd-555>",
|
||||
"event": "processed",
|
||||
"category": "cat facts",
|
||||
"sg_event_id": "sg_event_id",
|
||||
"sg_message_id": "sg_message_id"
|
||||
},
|
||||
{
|
||||
"email": "example@test.com",
|
||||
"timestamp": 1513299569,
|
||||
"smtp-id": "<14c5d75ce93.dfd.64b469@ismtpd-555>",
|
||||
"event": "deferred",
|
||||
"category": "cat facts",
|
||||
"sg_event_id": "sg_event_id",
|
||||
"sg_message_id": "sg_message_id",
|
||||
"response": "400 try again later",
|
||||
"attempt": "5"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
A reference to the second item in the array would look like this:
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "sendgrid",
|
||||
"execute-command": "{{ .Hookecho }}",
|
||||
"trigger-rule": {
|
||||
"match": {
|
||||
"type": "value",
|
||||
"parameter": {
|
||||
"source": "payload",
|
||||
"name": "root.1.event"
|
||||
},
|
||||
"value": "deferred"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## XML Payload
|
||||
|
||||
Given the following payload:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue