Message response filter

This filter gets (potentially) invoked for every response packet of type MSG.


Parameters

JSON expression : optional - a JSON expression. If specified, the filter will be invoked only if at least one of the sections in the packet matches the expression.

Section number : optional - a number (zero or above). If specified, and a JSON expression is also specified, then the JSON expression will be checked only in the specified section.


Context

The following variables will always be defined when your JavaScript executes:

  • log : the log object

  • context : contains all the variables you'll commonly use:

    • packet : the packet being filtered, which will always be an MSG packet

    • matchPath : if the JSON expression parameter is set, then this variable will be set to a list of strings representing the path to the first match in the object. In other words, this points out the reason why this object is being filtered. This is only useful if the JSON expression contains one or more * qualifiers. Note that these are strings, and therefore may need to be converted (typically using parseInt) if they represent numbers.

    • result : the result object, used to cancel the current packet if desired

    • filterContext: an object containing variables attached to this filter. Any changes to this object will be visible to all invocations of this filter.

    • connectionContext: an object containing variables attached to the connection. Any changes to this object will be visible to all filters defined on this connection.


Example

Let's assume that you want to intercept a certain type object that looks like this:

{
"name": "Jane Doe",
"labels": ["python","javascript","perl"],
"address": {
"street": "123 Main St",
"city": "Moose Lake",
"country": "Canada"
}
}

You can create a message response filter with the following JSON expression:

address.country=Canada;labels[+]=perl