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              |1       |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 another POST, posting of url-enoded array of values defined in the wiki.
!note We have to specify 'products\[]' as value name since the service requires a value called 'products[]' and the fixture interprets a value name ending on '[]' as an indicator the value is an array, and will normally not include that postfix in the name of the value sent to the service. By specifying '\[]' we indicate we ''don't'' want the brackets removed from the name.

|script        |json http test                                                                                           |
|set values    |televisie-start, internet-fiber-start|for                                               |products\[]     |
|post values to|https://thuis.t-mobile.nl/api/shoppingcart                                                               |
|show          |response                                                                                                 |
|check         |json path                            |error                                             |0               |
|check         |json path                            |$.fields.pricing_info.initial_onetime.pricing_info|Eenmalige kosten|
|check         |json path                            |$.fields.pricing_info.initial_monthly.pricing_info|Maandelijks     |

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|*                                               |
