07-27-2016 11:15 AM
Hi,
I have a requirement where I have to convert a string in XML format into corresponding JSON format.
The existing serializer does not recognise the tags and treats the entire string as one long text.
I tried using the XML parser( SMUM_XML_PARSE) which would return an internal table with the tags and corresponding values. JSON string generated from it treats the tags and values as value fields.
I would like to know whether my approach is right here or whether I should go about it differently. Also, I would appreciate some guidance on converting a string in XML format into corresponding JSON format.
Regards,
Renjith
07-27-2016 2:38 PM
One XML may correspond to several possibilities in JSON. I guess there could be a minimalist conversion function module (or whatever), but I feel it would be no sense, so my conclusion is that you always need a home made algorithm to convert. Why not with SMUM_XML_PARSE if it suits your requirement.
EDIT:
For instance, who knows if <tab><line>1<line></tab> is to be converted into {"tab":{"line":1}} or into {"tab":[{"line":"1"}]}
So you must create a program (see Horst answer)
PS: maybe a tool could be developped, which receives both XML + XSD, then it would be able to convert correctly.
07-27-2016 3:54 PM
If you want to do it in ABAP, you might
08-04-2016 10:06 AM