Extracting values from a JSON message containing XML

I’m trying to test an HTTP endpoint that requires input from another endpoint. A simplified response of the latter endpoint is:

)]}’,

{

“xmlMessage”:“<?xml version=\"1.0\" encoding=\"UTF-8\"?>BarValue”,

“token”:“aToken”

}

The other endpoint requires the value of “token” and the value of the “Bar” element found in “xmlMessage”.

At the moment I start by transforming the message to make it valid JSON (removing “)]}’,”), and then extract and save “token” and “xmlMessage” using jsonPath. Afterwards however, I don’t know how to extract the value of Bar from “xmlMessage” (using xpath?). When looking at the documentation I get the feeling that this isn’t possible, as it doesn’t follow the flow of:

  1. defining the check

  2. extracting

  3. transforming

  4. verifying

  5. saving

Could someone tell me if there’s a good way to realize this use case?

Thanks,

Jack

PS: Having an XML message as part of a JSON message is far from ideal, but this is something I can’t change.

You would extract the value of BAR using regular expression pattern matching.