JSONPath#

{{JSONPath "$…"}} extracts a field from the JSON request body. The body is parsed once per request; {{.Body}} still renders the full raw body string.

Syntax#

PathMeaning
$The whole request body (as JSON string)
$.userObject key user
$.user.nameNested object key
$.items[0]Array index 0
$.items[0].nameNested into an array element
$.items[1].tags[0]Deeper nesting

Return Semantics#

ValueRenders as
StringUnquoted (Ada)
NumberUnquoted (42, 42.5)
Booleantrue / false
nullnull
Object / arrayCompact JSON ({"a":1})
Missing path, out-of-bounds index, non-JSON bodyEmpty string (no panic, no fallback)

Example#

id: customer-echo
method: POST
path: /webhooks/customer-echo
response:
  status_code: 200
  template: true
  body: '{"received":{"id":"{{JSONPath "$.customer.id"}}","name":"{{JSONPath "$.customer.name"}}"},"full_payload":{{JSONPath "$"}}}'

Send a request:

curl -X POST http://localhost:8080/webhooks/customer-echo \
  -H "Content-Type: application/json" \
  -d '{"customer":{"id":"cust-42","name":"Ada Lovelace"}}'

Response:

{
  "received": {"id": "cust-42", "name": "Ada Lovelace"},
  "full_payload": {"customer":{"id":"cust-42","name":"Ada Lovelace"}}
}

Note the unquoted {{JSONPath "$"}} at the end — it renders the compact JSON object directly (numbers and booleans render unquoted, so this is safe for valid JSON request bodies).

Restrictions#

JSONPath keys are [A-Za-z0-9_-] only — no spaces, dots, or unicode in keys.

Not supported:

  • Filters: $.x[?(@.a)]
  • Wildcards: $.x[*]
  • Recursive descent: $..x
  • Negative indices: $.items[-1]

Worked Example#

stubs/template-showcase.yaml is a complete demo combining JSONPath extraction with faker generators:

curl -s -X POST http://localhost:8080/template-showcase \
  -H "Content-Type: application/json" \
  -d '{"customer":{"id":"cust-42","name":"Ada Lovelace"}}'

It echoes your customer.id / customer.name back while generating a realistic event body around them.