Example usage of making HTTP calls to get results in [[JSON][http://json.org]] notation and using [[!-JsonPath-!][http://goessner.net/articles/JsonPath/]] to validate the response's content.

First a simple GET request.

|script  |json http test                            |
|get from|http://echo.jsontest.com/key/value/one/two|
|show    |response                                  |
|check   |json path       |$.key       |value       |
|check   |json path       |$.one       |two         |


Then a POST, showing the multiple notations of !-JsonPath-! expressions supported (notice that adding the '$.' prefix is not required).

!define BAD_BODY { {{{
json={"key":"value"
}}} }

|script|json http test                                         |
|post  |${BAD_BODY}|to           |http://validate.jsontest.com/|
|show  |response                                               |
|check |json path  |$.validate   |false                        |
|check |json path  |validate     |false                        |
|check |json path  |.validate    |false                        |
|check |json path  |$['validate']|false                        |
|check |json path  |['validate'] |false                        |


Next another POST, showing that expressions resulting in a boolean or integer value are recognized and can be used accordingly by the script table. Furthermore expressions returning more than a single member are supported.

!define GOOD_BODY { {{{
json={"key":"value"}
}}} }

|script|json http test                                              |
|post  |${GOOD_BODY}         |to      |http://validate.jsontest.com/|
|show  |response                                                    |
|check |json path            |validate|true                         |
|ensure|json path            |validate                              |
|check |json path            |size    |>0                           |
|check |json path count      |$.*     |>=5                          |
|show  |all json path matches|*                                     |
|check |element              |4       |of json path   |$.*  |false  |


Next another POST, posting of url-enoded values defined in the wiki.

|script        |json http test                 |
|set value     |{"key":"value 2"}|for     |json|
|post values to|http://validate.jsontest.com/  |
|show          |response                       |
|check         |json path        |validate|true|

Next a PUT example
!define PUT_BODY { {{{
json={"id": 1,
    "title": "foo",
    "body": "bar",
    "userId": 1}
}}} }

|script|json http test                                                        |
|put   |${PUT_BODY}          |to |http://jsonplaceholder.typicode.com/posts/1/|
|show  |response                                                              |
|check |json path            |id |>0                                          |
|check |json path count      |$.*|>=2                                         |
|show  |all json path matches|*                                               |
