Forum Discussion
richie
3 years agoCommunity Hero
Hey oph_2022,
So your json response is contained within an array is that correct?
If you're talking about a json response then you could us an event handler (TestRunListener.afterStep) to remove the array container, but this would actually alter the response to malformed json (if the example payload youve included in your post).
The groovy would look something like the following:
content = content.replaceAll("\\[", "")
content = content.replaceAll("]", "")
Cheers,
Rich
- oph_20223 years agoOccasional Contributor
Hey Ritchie,
Thanks for your reply.
My json response is not contained within an array.
My JSON response is contained (Sequence Dispatch Style) here and i would like to know if i put the groovy code that you provied in your previous message can work here ?
Thanks,
Olivier,
- richie3 years agoCommunity HeroHey oph_2022,
Just to be clear, json arrays are represented by square brackets. All your payload content is contained within the square brackets, which means the whole content is saved within an array.
Youre using virts for your testing, right? Sorry i didn't realise this from your initial message. I've only used readyapi virts a couple of times, but yeah you can tailor your response with a script, but i must be misunderstanding something essential here, cos i dont understand why youd need to alter the hardcoded response via an event handler as you can specify exactly the response you want, without the need for an event handler as a post-processor before you assert.
Can you just explain your setup and use case a little more as i dont want to give you more incorrect info?
As you control in thr virt exactly the response youre trying to generate, what happens when you remove the array container brackets (both the [ and ])??
Cheers,
Rich
Related Content
- 7 years ago
- 8 years ago
Recent Discussions
- 19 days ago