hurl
hurl copied to clipboard
Support jsonpath subquery
Given the following html:
<!DOCTYPE html>
<html>
<body>
<p id="user"></p>
<script>
var s = '{"first_name" : "Sammy", "last_name" : "Shark", "location" : "Ocean"}';
var obj = JSON.parse(s);
document.getElementById("user").innerHTML =
"Name: " + obj.first_name + " " + obj.last_name + "<br>" +
"Location: " + obj.location;
</script>
</body>
</html>
I would like to be able to analyse the js s variable.
We could add a jsonpath subquery, that could work like this:
GET https://example.com/test.html
HTTP/* 200
[Asserts]
regex "var s = '(.*)';" jsonpath "$.first_name" == "Sammy"
regex "var s = '(.*)';" jsonpath "$.last_name" == "Shark"
regex "var s = '(.*)';" jsonpath "$.location" == "Ocean"
Or with an intermediate capture:
GET https://example.com/test.html
HTTP/* 200
[Captures]
s: regex "var s = '(.*)';"
[Asserts]
variable "s" jsonpath "$.first_name" == "Sammy"
variable "s" jsonpath "$.last_name" == "Shark"
variable "s" jsonpath "$.location" == "Ocean"
Catch in the wild with the following
- https://www.samsung.com/fr/trade-in/
<script>
var gnbNewModelJson = {"gnbLeftModelList:[{"displayName":"Offres","englishName":"offers","linkType":"move","displayFlag":"Y","mobileOnlyFlag":"N","menuPosition":"left","apiUseFlag":false,"ftImageUseFlag1":false,"ftImageUseFl...
See as a JSON:
{
"gnbLeftModelList": [
{
"displayName": "Offres",
"englishName": "offers",
"linkType": "move",
"displayFlag": "Y",
"mobileOnlyFlag": "N",
"menuPosition": "left",
"apiUseFlag": false,
}
]
}
The JavaScript variable gnbNewModelJson is returned by the backend, and the page is constructed with Angular.
- https://www.tesla.com/inventory/new/my?arrangeby=relevance&zip=95113&range=200
<script type="text/javascript">
window.tesla = {"App":{"app":"inventory-search-app","base_url":"https://www.tesla.com","host":"http://inventory-burst-app.tesla.com","language_direction":"LTR","locale":"en_US","strings":{"Chat":{"common":{"chatPreview":{"action__startChat":"Start Chat","content__haveQuestion":"Question about ordering a Tesla product?","content__supportLinkText":"If you are an existing customer, <a target=\"_blank\" href=\"/support/contact\">click here</a> for support.","label__close":"Close"}}}}},"debug":0,"filters":"{\"results\":{\"georegions\":{\"code\":\"georegions\",\"name\":\"Location\",\"type\":\"input\",\"accept\":\"string\",\"value\":\"\",\"availability\":[\"ms_used\",\"mx_used\",\"m3_used\",\"my_used\",\"ms_new\",\"mx_new\",\"m3_new\",\"my_new\"],\"custom\":true,\"choices\":[]},\"range\":{\"code\":\"range\",\"name\":\"Search within\",\"type\":\"dropdown\",\"ui_behavior\":{\"ignore_availability\":true},\"choices\":[{\"code\":25,\"name\":\"25 miles\",\"availability\":[]},{\"code\":50,\"name\":\"50 miles\",\"availability\":[]},{\"code\":100,\"name\":\"100 miles\",\"availability\":[]},{\"code\":200,\"name\":\"200 miles\",\"availability\":[]}],\"availability\":[\"
...
As a JSON:
{
"App": {
"app": "inventory-search-app",
"base_url": "https://www.tesla.com",
"host": "http://inventory-burst-app.tesla.com",
"language_direction": "LTR",
"locale": "en_US",
}
Instead of a subquery, we have now filters. @fabricereix We could implement this as a "jsonpath" filter, similar to xpath filter.
I've renamed the issue