Skip to content
CA API Gateway - 9.3
Documentation powered by DocOps

Evaluate JSON Path Expression V2 Assertion

Last update October 2, 2018

The Evaluate JSON Path Expression V2 Assertion is an improved version of the Evaluate JSON Path Expression Assertion. This improved assertion provides the following enhancements:

  • More intuitive results when querying JSON objects
  • New evaluators in the assertion properties:
    • SystemDefault
    • JsonPathWithCompression

Tip: Place a Protect Against JSON Document Structure Assertion before this assertion to protect against DOS attacks.

Context Variables Created by This Assertion

The Evaluate JSON Path Expression V2 assertion sets the following context variables. The default <prefix> is "jsonPath" and can be changed in the assertion properties.

Note: To learn about selecting the target message for this assertion, see Select a Target Message.

Variable Description
<prefix>.found 

Indicates whether a match was found for the expression:

  • true = Match found
  • false = No match found
<prefix>.count  Returns the number of matches.
<prefix>.result  Returns the result of the match, if a single match was made. 
<prefix>.results Returns the results of the match, if multiple matches were made.

Using the Evaluate JSON Path Expression Assertion V2

You can either add this assertion to your service or change the configuration of an existing assertion as follows:

  1. Do one of the following:
    • To add the assertion to the Policy Development window, see Add an Assertion. The Evaluate JSON Path Expression V2 Properties will automatically appear.
    • To change the configuration of an existing assertion, right-click <target>: Evaluate JSON Path Expression V2 in the policy window and select Evaluate JSON Path Expression V2 Properties or double-click the assertion in the policy window.
  2. Configure the evaluator and expression, as shown next:

    Setting Description
    Evaluator

    The following evaluators are supported:

    • System Default: The evaluator option is taken from the json.systemDefaultEvaluator Cluster-Wide Property. This is the default option. 
    • JsonPath
    • JsonPathWithCompression

      Note:

      • If you select JsonPath or JsonPathWithCompression, the value of cluster-wide property json.systemDefaultEvaluator is not considered.

      • If a JSON object contains a forward slash in the JSON object input, then a backslash is appended to the forward slash in the JSON output. To avoid this, set the evaluator as JsonPathWithCompression.

    Expression

    Enter the expression to be matched against a message. You may reference context variables.

    Note: The Expression field can only contain a single expression. To evaluate multiple expressions, configure multiple Evaluate JSON Expression assertions within a policy.

  3. Configure [Source and Destination] tab as follows:

    Setting Description
    Target Message

    Specify whether to match the Request, Response, or Other Message Variable that contains the value to analyze. If you select Other Message Variable option, enter the variable name in the text box. (You do not need to enclose the variable name within the "${ }" characters.)

    Tip: The message target can also be set outside of the assertion properties. For more information, see Select a Target Message.

    Variable Prefix Enter a prefix that is added to the context variables created by this assertion. This prefix ensures uniqueness and prevents the variables from overwriting each other when multiple instances of this assertion appear in a policy.
    For an explanation of the validation messages that are displayed, see "Context Variable Validation" in Context Variables.
  4. Select the [Test] tab to test your JSON expression against sample test input.

    • In the Test Input box, paste some JSON payload that might be found in the target message. When you click the [Test] button, the assertion evaluates the test input with the specified expression.
    • The Test Output box shows the results of the match. Examine the results carefully to see if this is what you intended. The following figure illustrates how the assertion interprets the test input given the sample expression shown:

      • For the test input shown in the figure, the test results are found = true and count = 2. This means that there were two inputs that fulfilled the criteria: Nigel Rees and Evelyn Waugh. The assertion was able to locate the author but not the category, title, or price, because they were not specified.
  5. Click [OK] when done.

Was this helpful?

Please log in to post comments.