Extracting numerical values from public or private JSON API responses can help you track and analyze data, easily spot trends, and alert on data that is important to your business. If you can passively have this information periodically come to you and if you can receive alert notifications when certain conditions are met, you can avoid checking each metric manually and – obviously – save a ton of time.
Synthetic monitoring tools let you do these things automatically. For more information about Synthetic monitoring applications and different use cases for extracting numbers and metrics from web pages and APIs, see how to periodically extract webpage performance metrics from browser API.
How to Extract Numerical Values from JSON API Responses Using Sematext
In this use case, we want to know the currency rate changes between the Euro, US Dollar, and GBP. The goal is to receive these rates periodically and create alert rules if the rates deviate from normal or go above or below a certain threshold.
If you are extracting data from a web page that returns HTML or if you are looking to collect a performance metric from a web browser API, use the Browser monitor. If you are extracting data from an API that returns JSON or XML, use the HTTP monitor. See best practices tips to make the best use of synthetic monitoring and keep your costs minimal. Note that HTTP monitors are cheaper than Browser Monitors.
Extracting Numerical Data via Browser Monitor User Journey Scripts
First you need to create a Synthetics App.
Then click to create a Browser Monitor to write a journey script that extracts currency rates from a public API. Synthetic monitors can be scheduled to run from multiple different public locations in a specified time interval. For what we’re aiming to do here, just one location is needed, and we’ll go with the longest interval for Browser Monitors – which is 1 hour. Just remember, the longest interval for HTTP monitors is 15 minutes, while for Browser monitors, it’s 1 hour. To save on costs, go for longer intervals when you want to see trends. But if you’re keeping an eye on performance and want to be notified of performance degradations ASAP, go for shorter intervals.
See best practices tips to make the best use of synthetic monitoring and keep your costs minimal.
You can choose the interval you want to extract currency rates periodically. And then write your user journey script.
Extracting Numerical Data via HTTP Monitor
Then enter the URL that you want to extract the metric from and choose the interval you want to extract currency rates periodically. Inside the “Configure Response” section, select either JSON or XML, depending on the format of the HTTP response body. Additionally, you can simulate and test the extraction by manually providing the response body.
In the screenshot above, we entered JSON paths to extract currency rates from the sample response. As a result, we saw the extracted values and then moved on to assigning names to these metrics.
Visualizing Extracted Data
Once you have defined your monitor to extract currency rates either with HTTP or Browser monitor, wait for the monitor to run a few times for the metrics to be recorded and taken into account. Then you will see the extracted metrics for each run in the run flyout.
Keep in mind that monitors run every few minutes. To ensure your chart looks great, adjust the Granularity in the “Axes” tab. Match it with the interval you picked for the monitor.
You can add more visualization to your Dashboard. Just click ‘Add Component’ at the top right and choose the component type that best suits your requirements.
Use Scheduled Reports to periodically send the Dashboard via email to yourself or your teammates.
Creating alert rules
Create alert rules when the extracted metric exceeds or goes below a certain threshold or deviates from the baseline and define priority for the alerts.
With Sematext Notification Hooks, you can choose from various platforms to receive alert notifications. Also, third-party integrations with various incident management platforms give you the ability to automatically create incidents, assign them to the responsible team, and define priorities to address issues or act on detected changes in the monitored APIs and websites.
In conclusion, Sematext Cloud provides a powerful way of extracting metrics from webpages, API endpoints, or browser APIs, visualizing them through charts, and setting up alerting rules. You can track changes in another website or API or your own.