I would like to seek an assistance how can I extract the value USDT on this sample response. Your response is highly appreciated. Currently this is how I extract my USDT using JSON Path tester $..currency[0]. I want to make it flexible without using number instead contains. is there's a way to simulate this? Thank you so much in advance
{ "uid": "123-321", "period": "25_minutes", "level": "symbol", "values": [ 1.3211, 1.2212 ], "rank_by": "volume", "currency": [ "USDT", "SGD" ], "measurements": [ 0.42, 0.15 ], "num_instruments": 20, "asset_classes": [ "All" ], "version": "1.0.0", "timestamp": "2022-05-30T03:53:09" }
Sample response I extracted:
CodePudding user response:
If you're uncertain about the order of currencies in the response you can consider
- Switching to
CodePudding user response:
Dont have clue about JSON extractor, but can be done through the following method,
- Add JSR223 Postprocessor as a child of the request which returns above JSON
- Put the following code into "Script" area
Script Block:
def jsonResponse = new groovy.json.JsonSlurper().parse(prev.getResponseData()) jsonResponse.each { getCurrencyArray -> def currencyExpected = "USDT" if(getCurrencyArray.getKey() == "currency"){ getCurrencyArray.getValue().each { curr -> if (curr.equalsIgnoreCase("USDT")) { vars.put("Cur", currencyExpected ) log.info("Cur = " currencyExpected) } } } }
With USDT: