Hello. Please help me figure out JSONPathPaginator...
# singer-tap-development
a
Hello. Please help me figure out JSONPathPaginator. The fact is that I started using it, and for some reason it returns me the id not of the last entry from the list, but of the first one. It's happening here
Copy code
def get_next(self, response: Response) -> str | None:
        """Get the next page token.

        Args:
            response: API response object.

        returns:
            The next page token.
        """
        all_matches = extract_jsonpath(self._jsonpath, response.json())
        return next(all_matches, None)
Here is my example
Copy code
[
   {
      id: 1
      dateTime: "11-10-2022T12:03:00"
   },
   {
      id: 2
      dateTime: "11-10-2022T12:04:00"
   },
   {
      id: 3
      dateTime: "11-10-2022T12:06:00"
   },
]
This function returns 1. But it would be logical for me if it returned 3 (so that in the next query I could put where id > 3 Please help me understand this moment. I understand that I can redefine this function and make it return the last element instead of the first one, but I want to understand why this function was originally described so that it returns the first element? (Perhaps it is described for the case of sorting in descending order?)
r
You could use a different JSONPath expression like
-1:.id
.
a
wow, nice! However, I'm still wondering how your version works. Are you using desc or asc by default? Do you have the latest events on the first or last page?
r
We are explicitly requesting the single oldest log when the
JSONPathPaginator
logic is applied. So naturally, it is the first, last and only result.
a
As far as I understand your logic is as follows. At the first request, you check if there is a last_log_id, if it is, then you use it If it is not there, then you are asking to receive only one event (the very first (oldest)) - for example, this is id=3 Then you expect that you have last_log_id and it is equal to 3 right?
r
Correct. 🙂
a
Ok, I need to do almost the same, now I'll try to figure it out
thnaks!!!
r
a
I have changed "$[*].Id" to "-1:.Id" And start recieve error in parser Where i can read something about this syntax?
r
-1:.id
worked for that previous example data you sent (the root element was an
[]
), but no guarantee it matches to format of your real data. Have a look at https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html and test with https://jsonpath.com/.
a
message has been deleted
Everything seems to work in the sandbox
But in tap, i recieve error
Are there alternative ways to debug this error? The thing is that I have the correct response (same as in the sandbox), but I still get the error Parse error at 1:2 near token : (:)
r
message has been deleted
a
I just tried another variant which is more similar to the previous one. next_page_token_jsonpath = "$[(@.length-1)].Id" and got the error again
The error in your screenshot is different from the one I get
r
Try
$[-1:].Id
.
a
No erros and no records
but it empty also on sandbox
r
You need the
$
.
a
sure. Moment
It seems to work, but honestly I don't understand why.
r
Just do some reading on JSONPath syntax. I usually figure it out by trial and error.
a
I got you. thanks a lot