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

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://thuisbestellen.vodafone.nl/api/shoppingcart                                              |
|show          |response                                                                                         |
|check         |json path                            |error                                        |0            |
|check         |json path                            |$.fields.order.basic_products[0].product_name|Internet 50Mb|
|check         |json path                            |$.fields.order.basic_products[1].product_name|TV Start     |

Next a POST/DELETE combination

|script                |json http test                                 |
|set value             |dsfsdf         |for                |name       |
|set value             |2010           |for                |year_formed|
|set value             |1              |for                |genre_id   |
|set value             |Afghanistan    |for                |country    |
|post values as json to|http://rest.kabasakalis.tk/api/artist          |
|show                  |request                                        |
|check                 |response status|200                            |
|show                  |response                                       |
|$id=                  |json path      |data.artist.id                 |
|check                 |json path      |data.artist.name   |dsfsdf     |
|check                 |json path      |data.artist.country|Afghanistan|
|delete                |http://rest.kabasakalis.tk/api/artist/$id      |
|check                 |response status|200                            |
|show                  |response                                       |
|check                 |json path      |success            |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|*                                     |<commit_msg>Remove usage of REST service which is no longer available. Fix expected value<commit_after>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|*                                     |

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://thuisbestellen.vodafone.nl/api/shoppingcart                                                        |
|show          |response                                                                                                   |
|check         |json path                            |error                                             |0                 |
|check         |json path                            |$.fields.pricing_info.initial_onetime.pricing_info|Eenmalig betaal je|
|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|*                                               |
{'fraction_non_alphanumeric': 0.09400572831423895, 'fraction_numerical': 0.0033756137479541734, 'mean_word_length': 1.1511551155115511, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2895300', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2209, 'n_words': 753}