Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert XML string to JSON format

0 Likes
8,618

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

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,233

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.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
3,233

If you want to do it in ABAP, you might

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
3,233

I've written an example, how one could do it in ABAP now, see