Using JSONPath
Introduction
JSONPath ↗ is a query language for JSON, similar to how XPath works for XML. In Formcrafts, JSONPath is used in different places, such as in webhooks, to extract specific values from JSON responses. You can test your JSON paths using this tool ↗.
Basic syntax
JSONPath expressions always start with $ which represents the root of the JSON document. You then use dot notation or bracket notation to navigate through the structure.
| Expression | Description |
|---|---|
| $ | Root object |
| . | Child operator |
| [] | Array index or child operator |
Examples
Given this JSON response:
{
"status": "completed",
"user": {
"id": "usr_12345",
"name": "John Doe",
"email": "[email protected]"
},
"order": {
"id": "ord_67890",
"total": 79.98,
"items": [
{ "name": "Product A", "price": 29.99 },
{ "name": "Product B", "price": 49.99 }
]
}
}Accessing simple properties
| JSONPath | Result |
|---|---|
| $.status | completed |
| $.user.id | usr_12345 |
| $.user.name | John Doe |
| $.order.total | 79.98 |
Accessing array elements
If you are trying to use JSONPath to fetch a list of options (such as in a dropdown field, or table field) you would be asked for Option List Path, and then relative paths.
Take this data for example:
{
"products": [
{ "id": "prod_1", "name": "Product A" },
{ "id": "prod_2", "name": "Product B" },
{ "id": "prod_3", "name": "Product C" }
]
}The Option List Path would be:
| JSONPath | Result |
|---|---|
| $.products[*] | products array (option list path) |
The relative paths for value and label would be:
| JSONPath | Result |
|---|---|
| $.id | prod_1, prod_2, prod_3 |
| $.name | Product A, Product B, Product C |
Using multiple paths
In Formcrafts webhook configuration, you can extract multiple values by separating JSONPath expressions with commas:
$.data.id, $.data.status, $.meta.timestampEach extracted value becomes available for use in subsequent workflow actions.
Notes
JSONPath expressions are case-sensitive. $.User.Id is different from $.user.id.
If a path doesn’t match anything in the response, no value is extracted (no error is thrown).
JSONPath only works with JSON responses. If your webhook returns a different content type, values cannot be extracted.
