1
response

i am getting data from a database, one of these fields containts an xml, is it possible to convert this single field to json?

sample data
{
"id": 27101,
"ResponseStatus": "SUCCESS",
"RequestTime": "2018-09-19 14:21:48",
"ResponseXml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"><Header /><Body><from>Jani</from></Body></Envelope>\r\n",
"RequestMode": "DSS",
"ErrorCode": null,
}

i want the ResponseXml field to be converted to json aswell, i also want to keep the other fields

or any other sollution to parse the xml so i have access to the data inside the xml

thx!

AskedSeptember 19, 2018 - 2:37pm

Answer (1)

There are a couple options:

  1. Use parse_xml($ResponseXml);
  2. Use xm_perl or xm_python.
  3. If the data is simple using a plain regexp might do: $ResponseXml =~ /\<from\>(?<From>\S+)\<\/from\>/;