Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support jsonpath filter #440

Closed
jcamiel opened this issue Jan 13, 2022 · 2 comments
Closed

Support jsonpath filter #440

jcamiel opened this issue Jan 13, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jcamiel
Copy link
Collaborator

jcamiel commented Jan 13, 2022

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"
@jcamiel jcamiel added the enhancement New feature or request label Jan 21, 2022
@fabricereix fabricereix added this to the 1.7.0 milestone Feb 10, 2022
@jcamiel jcamiel removed this from the 1.7.0 milestone Sep 12, 2022
@jcamiel
Copy link
Collaborator Author

jcamiel commented Apr 7, 2023

Catch in the wild with the following

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

<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",
}

@jcamiel
Copy link
Collaborator Author

jcamiel commented Oct 3, 2023

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

@jcamiel jcamiel added this to the 4.2.0 milestone Oct 3, 2023
@jcamiel jcamiel changed the title Support jsonpath subquery Support jsonpath filter Oct 3, 2023
@fabricereix fabricereix self-assigned this Nov 8, 2023
@fabricereix fabricereix linked a pull request Nov 8, 2023 that will close this issue
@jcamiel jcamiel closed this as completed Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants