Mockoon Response Rule Triggers: Targets, Paths, and Dynamic Values
Quick answer: In Mockoon, a response rule trigger is a condition on a request value such as a JSON body path, query parameter, header, cookie, route parameter, request number, variable, data bucket, or template result. Each response owns a rule group; Mockoon checks responses top to bottom and serves the first matching group, using OR inside a group by default with AND optional. Rules select a response on an already matched route, not the route itself.
Rule parts and evaluation order
Every rule row has a target, property or path, invert toggle, operator and expected value. Rules are unlimited and draggable, and the exclamation mark inverts a comparison. Across responses, the first true group wins, so a response with no rules acts as the catch-all and belongs last. Random and sequential response modes skip rule evaluation, and the rules-disabled toggle forces the default response; that toggle cannot combine with random or sequential mode.
What a rule can inspect
Most targets need a property name or path; path, method and request number do not.
| Target | Property field | Typical use |
|---|---|---|
| Body | Object-path or JSONPath; blank for the whole parsed body | Match a JSON, form or XML field |
| Query string | Parameter name or nested path such as filter.primary |
Branch on filters or repeated keys |
| Header | Header name such as Accept |
Content negotiation and feature flags |
| Cookie | Cookie name such as Session-id |
Fixture session branches |
| Route parameter | Name without the colon, so :userId becomes userId |
Branch on a captured ID |
| Path, method, request number | No property field | Match /users/42, lowercase post, or call index |
| Global variable | Name plus optional path | Use state set earlier in the mock |
| Data bucket content | Bucket name plus optional path | Compare stored records or a schema |
| Custom templating | Helper expression | Compare a derived string such as a JWT claim |
Request number starts at 1, can be reset through the state purge admin API, and accepts a regex such as ^[1-3]$ for the first three calls.
Nested paths, arrays and dynamic values
Body paths use object-path or JSONPath Plus; escape dots in object-path property names. Leave the path blank to compare the whole parsed body, available for JSON, application/x-www-form-urlencoded, multipart/form-data, XML and SOAP. Multipart covers text fields only and ignores uploaded files, while XML is parsed with xml-js. Query parsing uses qs, including nested objects and arrays. When a body or query property resolves to an array, Mockoon matches if at least one item equals the value, so point at the array itself, such as tags equals vip, instead of addressing a fixed index.
Both the property and value fields accept templating helpers, so an expected value can come from the request or mock state. The custom templating target evaluates an expression to a string, for example {{jwtPayload (header 'Authorization') 'sub'}}, and has no array operators. The operator set is equals, regex match, null, empty array, array includes and valid JSON schema. Null fits absent headers or cookies; a schema value points to an ajv schema stored in a data bucket. Regex values omit leading and trailing slashes, as in ^user1-9.
Where triggers stop
Rules run after routing: a wrong path or method returns 404 before any rule is evaluated. A regex checks text shape, not credential validity, and schema validation guards one fixture value rather than deploying the real backend. If a rule misses, check response order, the OR/AND choice, the response mode, and whether the property path resolves. The request log shows the selected response or a fallback-proxy forward.
Powerduck checks the same conditional behavior from the caller side. Its scenario runner sends an ordered request sequence, passes values between steps, and asserts status, headers and response fields at each one, then exports a self-contained HTML report. That exercises a triggered branch across a flow instead of configuring isolated responses. The broader trade-offs against standalone mock servers are in our comparison hub.
Frequently asked questions
How do I match a nested JSON body field? Choose the Body target and enter an object-path or JSONPath expression such as user.id. Leave the path blank for the whole parsed body, and use a supported JSON, form or XML content type.
Can a rule compare against a variable? Yes. Property and value fields support templating helpers, global variables and data buckets are targets, and custom templating evaluates an expression to a string.
Why are my rules being ignored? A broader response may sit above a specific one, the group logic may be wrong, or the route may be in random, sequential or rules-disabled mode. A path or method mismatch fails routing before rules run.
The bottom line
Treat triggers as ordered conditions over request data and local mock state. Pick the narrowest target, use an explicit path, rely on automatic array membership, and keep specific groups above the catch-all, then exercise the branches with an ordered request sequence. A trigger proves the mock returns the configured fixture; it does not prove the real service makes the same decision.