JSON handling
JSONPath actions support JSON manipulation on HTTP requests and responses. HTTP responses are stored in a special variable (see Variables) to avoid the user having to store and retrieve on following checks. See HTTP for information on the format of the HTTP responses.
Currently, only two kind of queries are allowed with JSONPath:
- Nested object/member expressions:
store.book
- Array expression:
store.book[1].title
- Array index starts at 0
random
chooses a random index in the length of the array:store.book[random].title
JSONPath will be extended to support more XPath-like expressions.
Is member
The jsonpath-member
action checks that the element pointed by path
is defined in object
. Returns a boolean.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
action | No | Yes | Action that evaluates to a JSON object. If it is not present, it will use as input the answer from the last HTTP request. |
path |
string | Yes | No | JSONPath |
Example
{"jsonpath-member" : {
"path" : "body.customer.active_card.type"
}
}
Are members
The jsonpath-members
action checks that the elements pointed by paths
are defined in object
. Returns a boolean.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
action | No | Yes | Action that evaluates to a JSON object. If it is not present, it will use as input the answer from the last HTTP request. |
paths |
list of string | Yes | No | List of JSONPathath |
Example
{"jsonpath-members" : {
"paths" : ["body.customer.active_card.type",
"body.customer.active_card.exp_month"]
}
}
Value
The jsonpath-value
action checks that the element pointed by path
in object
contains the value of value
. Returns a boolean.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
action | No | Yes | Action that evaluates to a JSON object. If it is not present, it will use as input the answer from the last HTTP request. |
path |
string | Yes | No | JSONPath |
value |
json basic | Yes | No | The expected JSON value |
Example
{"jsonpath-value" : {
"path" : "customer.active_card.type"
"value" : "VISA"
}
}
Get
The jsonpath-get
action gets the value pointed by path
in object
and stores it in the variable
. The value stored in the variable can be recovered with var-get
action. If the path
does not exist, an empty binary is returned.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
action | No | Yes | Action that evaluates to a JSON object. If it is not present, it will use as input the answer from the last HTTP request. |
path |
string | Yes | No | JSONPath |
variable |
string | Yes | No | Variable name |
Example
{"jsonpath-get" : {
"path" : "body.customer.active_card.type"
"variable" : "CardType"
}
}
Set
The jsonpath-set
action sets the element pointed by path
in object
to the value of value
. Can be used as the body of a HTTP request.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
string | Yes | No | JSON object represented as a string |
path |
string | Yes | No | JSONPath |
value |
json basic | Yes | Yes | Variable name |
Example
{"jsonpath-set" : {
"object" : "{\"customer\" : {\"active_card\" :
{\"type\" : \"Visa\",
\"exp_month\" : 6},
\"email\" : \"me@me.com\"
}
}",
"path" : "customer.active_card.type"
"value" : "MasterCard"
}
}
Multiset
The jsonpath-multiset
action sets a list of pairs \{path, value\
} on the object
. The element pointed by path
in object is replaced by value
. It can be used as the body of a HTTP request.
Name | Type | Required | Action | Info |
---|---|---|---|---|
object |
string | Yes | No | JSON object represented as a string |
pairs |
List of pair objects | Yes | No | List of objects containing path and value |
The pair
action:
Name | Type | Required | Action | Info |
---|---|---|---|---|
path |
string | Yes | No | JSONPath |
value |
json basic | Yes | Yes | Variable name |
Example
{"jsonpath-multiset" : {
"object" : "{\"customer\" : { \"active_card\" :
{\"type\" : \"Visa\",
\"exp_month\" : 6},
\"email\" : \"me@me.com\"
}
}",
"pairs": [
{
"path" : "customer.active_card.type"
"value" : "MasterCard"
}
]
}
}