JSON + Regex Monitoring

I’ve been using Distill for a few years but recently wanted to explore the best way to track value changes in APIs. I am trying to monitor flights via JetBlue APIs

Sample API Link: https://jbrest.jetblue.com/bff/bff-service/bestFares/?apiKey=dummy&origin=EWR&destination=SJU&fareType=LOWEST&month=FEBRUARY%202024&tripType=ONE_WAY&adult=2&child=0&infant=0

The idea is to notify when prices for any date drop below 100 or a specific price (e.g., 175). I used regex101 to build the regex expression and the below expression was provided:

/"amount":\b(0*(?:[1-9][0-9]?|175))\b/gim

Per the sample API Link provided above, I should get “3” matches in the text.

Below is how I configured the expression in Distill:

I presume there is a better way to do this so any input is greatly appreciated it. Perhaps I should be using the Monitor “JSON” functionality?

Hey @wilito92,

Can you please test once after replacing the character in your regex with " so that the regex becomes "amount":\b(0*(?:[1-9][0-9]?|175))\b?

Here’s a screenshot from my setup:

The matches regular expression condition tests whether the text matches the expression. It will not update the monitor’s data. You can check the result of the condition in the Monitor’s data view:
image

If you only want to capture the data matching regex then you can add the Regex Filter in the config:

It will only extract the matching text:

We can create a JSON Monitor too for this scenario with the same URL and the matches regular expression condition.

Let me know if this helps.

1 Like

So the issue I have now is that sometimes values for different dates “change” but those dates are not under $100 but I still get the alert because the dates that did not change are still under $100. So I get a notification because the overall text change but not for a new date that is under $100. This is because I was using the “Text” aspect.

I now changed it to “Added text” and now have the issue that sometimes only 2 number in the price change. For example, it changes from $175 to $165. The text that changed is only the first two numbers “17” to “16”, therefore the alert is triggered because the added text of “16” is less than 100 but in reality the price is still not less than 100.

What is the best way to successfully resolve this?

Hey @wilito92,

I’ve created a Webpage Monitor with the following regex filter:

(currencyCode)|("amount":\b(0*(?:[1-9][0-9]?|175))\b)|(amount)

and a condition Text has number more than (>) 0.

For each fare entry, the regex will:

  • try to check if the amount value is less than 100 or equal to 175
    • if it matches then pick that amount
    • otherwise, pick a blank amount

This regex can create text with different values while keeping the fare order info intact.

For example,

  • If none of the fares match the regex, the text output will be:


    The notification will not be triggered as it doesn’t contain any number.

  • If there’s a fare with one amount value being 175, the text output will be:


    The notification will be triggered.

  • If there’s a fare with an amount < 100, the text output will be:


    The notification will be triggered.

    • If there’s a new change after the previous one in which the price for a different fare entry changes from 250 to 254 then it won’t be saved because the regex output will remain the same.

Here’s my Monitor config:

and condition:

I’ve added currencyCode in regex so that it matches currencyCode text every time, even if outboundFare is blank. This way we won’t get SELECTION_EMPTY error. You can remove it if that’s not required.

Let me know if this helps

1 Like