Apidog supports visually extracting values from the API response and saving them as variables.
To get started to extract variables, follow these steps:
In the Run tab (DESIGN Mode) or Request tab (DEBUG Mode), navigate to Post Processors.
Hover over "Add PostProcessor" and select "Extract Variable".
![image.png](https://api.apidog.com/api/v1/projects/544525/resources/342755/image-preview)
Enter the Variable Name and choose the Variable Scope.
Select the extraction source, such as Response JSON, Response XML, or Response Text, etc.
If the response is in JSON/XML format, you can utilize JSONPath/XPath syntax to parse a specific part of the Response JSON/XML and save it as the value of the variable.
![image.png](https://api.apidog.com/api/v1/projects/544525/resources/342756/image-preview)
After clicking "Send" to send the request, the variable extraction will be executed, and you can view the logs in the Console.
![image.png](https://api.apidog.com/api/v1/projects/544525/resources/342758/image-preview)
To quickly extract variables from the actual response, hover over the response field(e.g., on endpoint response or test reports), and click onExtract variable
.
![image.png](https://api.apidog.com/api/v1/projects/544525/resources/348242/image-preview)
Apidog supports extracting data from various data sources. Below are the different data sources from which data extraction is supported:
Response text: Supports extracting data using Regex expressions.
Response JSON: Supports extracting data using JsonPath expressions.
Response XML: Supports extracting data using XPath expressions.
Response Header: Extract from header name.
Response cookie: Extract from cookie name.
Time Consuming: Extract the time taken for request execution, providing insights into request response times and performance metrics for analysis and optimization purposes.
JSON is the most commonly used response data format, and JSONPath is a widely used syntax for data extraction within JSON structures. Apidog provides a visual JSONPath Extraction tool to simplify the process of crafting JSONPath expressions. Here is a guide on how to use this tool effectively:
Click on the icon located to the right of the JSONPath input box.
In the JSONPath Extraction tool that pops up, the left section displays the JSON response. You can input your JSONPath expression in the JSONPath Expression field at the top right. The results section at the bottom will dynamically extract the corresponding data based on your expression.
![image.png](https://api.apidog.com/api/v1/projects/544525/resources/342817/image-preview)
If your JSONPath expression includes wildcard characters (*) or similar elements that may result in extracting multiple values, the results will be enclosed within square brackets ([]). If you wish to extract a specific value and **avoid the brackets**, you can toggle the "**Continue extracting**" switch and specify the index of the value you want to extract.