JSON is a commonly used data format that is used in web based applications. The JMeter JSON Extractor provides a way to use JSON Path expressions for extracting values from JSON-based responses in JMeter. This post processor must be placed as a child of the HTTP Sampler or for any other sampler that has responses.
To use this component, open the JMeter menu and: Add -> Post Processors -> JSON Extractor.
The JSON Extractor is very similar to the Regular Expression Extractor. Almost all the main fields are mentioned in that example. There is only one specific JSON Extractor parameter: ‘Compute concatenation var’. In case many results are found, this extractor will concatenate them by using the ‘,’ separator and storing it in a var named _ALL.
Let’s assume this server response with JSON:
{
"store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
The table below provides a great example of different ways to extract data from a specified JSON:
Through this link you can find a more detailed description of the JSON Path format, with related examples.