diff --git a/lib/engine_http.js b/lib/engine_http.js index 39be630..781e185 100644 --- a/lib/engine_http.js +++ b/lib/engine_http.js @@ -337,8 +337,12 @@ function dummyParser(body, callback) { // doc is a JSON object function extractJSONPath(doc, expr) { - let result = jsonpath.eval(doc, expr)[0]; - return result; + let results = jsonpath.eval(doc, expr); + if (results.length > 1) { + return results[randomInt(0, results.length - 1)]; + } else { + return results[0]; + } } // doc is an libxmljs document object @@ -367,3 +371,7 @@ function extractRegExp(doc, expr) { function dummyExtractor() { return ''; } + +function randomInt (low, high) { + return Math.floor(Math.random() * (high - low + 1) + low); +}