This video tutorial demonstrates, how you may use JSON path in vREST.
<iframe width="560" height="315" src="https://www.youtube.com/embed/rBzqqimP2ig?list=PLmua155_WrDyoe7dYDB3lCfh-UK4XicT6?ecver=1" frameborder="0" allowfullscreen></iframe> |
JSON Path is used to locate the data in JSON object. JSON Path is currently used in the following two functionalities of vREST:
Note: We are using jsonPath version 0.8.5. Just remove the prefixes "$."
in case of JSON object and "$
" in case of top level JSON array while defining JSON path expressions in vREST.
Below are some examples of most common scenarios for JSON path expressions.
For JSON Object Data
Below is the sample JSON Object for reference.
{ "summary": "Sample Test Case ...", "method": "GET", "url": "http://localhost:3000/sample-test-case", "expectedResults": { "statusCode": 200, "headers": [ { "value": "Mon, 27 Jul 2015 06:38:31 GMT", "name": "Date" }, { "value": "application/json", "name": "Content-Type" } ] }, "createdAt": "2015-02-09T08:22:18.000Z", "version.0": "Version 0", "version.1": "Version 1" } |
method
GET
expectedResults.statusCode
200
expectedResults.headers.0.name
Date
To verify the headers array length
JSON Path Expression: expectedResults.headers.length
Value: 2
When key also having a dot (Use Square Brackets)
JSON Path Expression
['version.0']
Value: Version 1
For JSON Array Data
Below is the sample JSON Array for reference.
[ { "summary": "Sample Test Case 1", "method": "GET", "url": "http://localhost:3000/sample-test-case1" }, { "summary": "Sample Test Case 2", "method": "GET", "url": "http://localhost:3000/sample-test-case2" }, { "summary": "Sample Test Case 3", "method": "GET", "url": "http://localhost:3000/sample-test-case3" } ] |
[0].method
GET
length