Sample JSON Expressions for Data Extraction
When using variables or assertions that extract data from JSON bodies, you'll need to specify a JSON object expression to locate the data to extract. Here are some examples.
Sample Object Data
{ "firstName": "Grace", "lastName": "Hopper", "age": 107, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": 10021 }, "phoneNumbers": [ { "type": "home", "number": "212-555-1234" }, { "type": "mobile", "number": "646-555-4567" } ] }
Example 1: Top-level property
Expression: lastName
Value: Hopper
Example 2: Nested property
Expression: address.city
Value: New York
Example 3: Nested property within array
Expression: phoneNumbers[0].number
Value: 212-555-1234
Example 4: Nested property within last element of array
Expression: phoneNumbers[-1].number
Value: 646-555-4567
Sample Array Data
[ { "type": "home", "number": "212-555-1234" }, { "type": "mobile", "number": "646-555-4567" }, { "type": "work", "number": "651-555-0000" } ]
Example 1: Object property within root-level array
Expression: [2].number
Value: 651-555-0000
Example 2: Retrieve the type of the second to last item in the array
Expression: [-2].type
Value: mobile