convert field containig xml to json

Tags:

#1 w.schmitt@evidos.nl

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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>\r\n<Envelope xmlns=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;><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!

#2 b0ti Nxlog ✓ (Last updated )
#1 w.schmitt@evidos.nl
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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>\r\n<Envelope xmlns=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;><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!

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\>/;