2021-09-21 07:36:53 +03:00
|
|
|
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Options]</span></span>
|
2023-04-17 14:05:34 +03:00
|
|
|
<span class="line"><span class="string">variable</span>: one=<span class="number">1</span></span>
|
|
|
|
<span class="line"><span class="string">variable</span>: two=<span class="number">2</span></span>
|
|
|
|
<span class="line"><span class="string">variable</span>: three=<span class="number">3</span></span>
|
|
|
|
<span class="line"><span class="string">variable</span>: four=<span class="number">4</span></span>
|
|
|
|
<span class="line"><span class="string">variable</span>: five=<span class="number">5</span></span>
|
|
|
|
<span class="line"><span class="string">variable</span>: foo=<span class="string">abc</span></span>
|
|
|
|
<span class="line"><span class="string">insecure</span>: <span class="boolean">false</span></span>
|
2023-07-25 12:47:36 +03:00
|
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Captures]</span></span>
|
2023-04-17 14:05:34 +03:00
|
|
|
<span class="line"><span class="name">count</span>: <span class="query-type">jsonpath</span> <span class="string">"$.count"</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">==</span> <span class="number">5</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">==</span> <span class="number">5.0</span></span>
|
2022-09-01 22:20:20 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">==</span> <span class="expr">{{five}}</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">!=</span> <span class="number">4</span></span>
|
2022-09-01 22:20:20 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">!=</span> <span class="expr">{{four}}</span></span>
|
2023-06-01 10:24:52 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="not">not</span> <span class="predicate-type">==</span> <span class="number">4</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">></span> <span class="number">1</span></span>
|
2022-09-01 22:20:20 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">></span> <span class="expr">{{one}}</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.count"</span> <span class="predicate-type">></span> <span class="number">1.0</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">==</span> <span class="boolean">false</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">!=</span> <span class="null">null</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">exists</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.success"</span> <span class="predicate-type">isBoolean</span></span>
|
2022-10-25 09:59:18 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">2</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors"</span> <span class="predicate-type">isCollection</span></span>
|
2023-05-05 08:57:36 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.failures"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">1</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.failures"</span> <span class="predicate-type">isCollection</span></span>
|
2022-10-25 09:59:18 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">0</span></span>
|
2023-03-10 18:23:28 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">isEmpty</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.toto"</span> <span class="not">not</span> <span class="predicate-type">exists</span></span>
|
2023-05-05 08:57:36 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.failures"</span> <span class="predicate-type">exists</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.warnings"</span> <span class="predicate-type">exists</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]"</span> <span class="predicate-type">exists</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]"</span> <span class="predicate-type">isCollection</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0].id"</span> <span class="predicate-type">==</span> <span class="string">"error1"</span></span>
|
2023-07-25 17:31:36 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0].id"</span> <span class="predicate-type">isString</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]['id']"</span> <span class="predicate-type">==</span> <span class="string">"error1"</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[*].id"</span> <span class="predicate-type">includes</span> <span class="string">"error1"</span></span>
|
2023-05-05 08:57:36 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[?(@.id=='error1')].id"</span> <span class="filter-type">nth</span> <span class="number">0</span> <span class="predicate-type">==</span> <span class="string">"error1"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.failures[*].id"</span> <span class="predicate-type">includes</span> <span class="string">"failure1"</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">==</span> <span class="number">1.5</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type"><=</span> <span class="number">2.0</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type"><</span> <span class="number">2</span></span>
|
2022-09-01 22:20:20 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type"><</span> <span class="expr">{{two}}</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="predicate-type">isFloat</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.duration"</span> <span class="not">not</span> <span class="predicate-type">isInteger</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.nullable"</span> <span class="predicate-type">==</span> <span class="null">null</span></span>
|
2022-09-09 17:54:28 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags[0]"</span> <span class="predicate-type">==</span> <span class="string">"test"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags[0]"</span> <span class="predicate-type">></span> <span class="string">"te"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags[0]"</span> <span class="predicate-type"><</span> <span class="string">"testabc"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags[0]"</span> <span class="predicate-type"><=</span> <span class="string">"test"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags[0]"</span> <span class="predicate-type">></span> <span class="string">"{{foo}}"</span></span>
|
2023-01-17 20:37:31 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.profile-id"</span> <span class="predicate-type">==</span> <span class="string">"123abc"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$['profile-id']"</span> <span class="predicate-type">==</span> <span class="string">"123abc"</span></span>
|
2023-07-25 12:47:36 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[0]"</span> <span class="not">not</span> <span class="predicate-type">isEmpty</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.empty"</span> <span class="predicate-type">isEmpty</span></span>
|
|
|
|
<span class="line"></span><span class="comment"># FIXME do we accept count filter on object?</span>
|
|
|
|
<span class="line"></span><span class="comment"># jsonpath "$.empty" count == 0</span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="json"><span class="line">{</span>
|
|
|
|
<span class="line"> "count": 5,</span>
|
|
|
|
<span class="line"> "success": false,</span>
|
|
|
|
<span class="line"> "errors": [{"id":"error1"},{"id":"error2"}],</span>
|
2023-05-05 08:57:36 +03:00
|
|
|
<span class="line"> "failures": [{"id":"failure1"}],</span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"> "warnings": [],</span>
|
|
|
|
<span class="line"> "duration": 1.5,</span>
|
|
|
|
<span class="line"> "tags": ["test"],</span>
|
2023-01-17 20:37:31 +03:00
|
|
|
<span class="line"> "nullable": null,</span>
|
2023-07-25 12:47:36 +03:00
|
|
|
<span class="line"> "profile-id": "123abc",</span>
|
|
|
|
<span class="line"> "empty": {}</span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line">}</span></span>
|
|
|
|
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
2023-07-25 12:47:36 +03:00
|
|
|
<span class="line"></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/index</span></span>
|
2022-11-11 16:25:00 +03:00
|
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Captures]</span></span>
|
2023-04-17 14:05:34 +03:00
|
|
|
<span class="line"><span class="name">index</span>: <span class="query-type">body</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
2023-07-25 12:47:36 +03:00
|
|
|
<span class="line"></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json</span></span>
|
2022-11-11 16:25:00 +03:00
|
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.errors[{{index}}].id"</span> <span class="predicate-type">==</span> <span class="string">"error2"</span></span>
|
2021-09-21 07:36:53 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> <span class="predicate-type">includes</span> <span class="string">"test"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> <span class="not">not</span> <span class="predicate-type">includes</span> <span class="string">"prod"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.tags"</span> <span class="not">not</span> <span class="predicate-type">includes</span> <span class="null">null</span></span>
|
|
|
|
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
|
|
|
<span class="line"></span>
|
|
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/list</span></span>
|
2022-11-11 16:25:00 +03:00
|
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
2022-10-25 09:59:18 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$"</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">2</span></span>
|
2022-03-28 19:04:35 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.[0].name"</span> <span class="predicate-type">==</span> <span class="string">"Bob"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$[0].name"</span> <span class="predicate-type">==</span> <span class="string">"Bob"</span></span>
|
2023-05-22 18:18:09 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.[?(@.id == 1)].name"</span> <span class="filter-type">nth</span> <span class="number">0</span> <span class="predicate-type">==</span> <span class="string">"Bob"</span></span>
|
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$[?(@.id == 1)].name"</span> <span class="filter-type">nth</span> <span class="number">0</span> <span class="predicate-type">==</span> <span class="string">"Bob"</span></span>
|
2021-12-20 00:56:04 +03:00
|
|
|
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
2023-07-25 12:47:36 +03:00
|
|
|
<span class="line"></span>
|
2021-12-20 00:56:04 +03:00
|
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-json/filter</span></span>
|
2022-11-11 16:25:00 +03:00
|
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
2023-04-11 18:28:28 +03:00
|
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
2023-06-01 10:24:52 +03:00
|
|
|
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.fruit[?(@.price.US==200)].name"</span> <span class="filter-type">nth</span> <span class="number">0</span> <span class="predicate-type">==</span> <span class="string">"grape"</span></span>
|
2022-10-24 12:37:11 +03:00
|
|
|
</span></span></code></pre>
|