Reputation: 145
I'm trying to convert an XML file into an internal table of type String
.
Is there a function module to convert XML data to JSON format?
Upvotes: 0
Views: 3746
Reputation: 41
Using a ABAP simple transformation or an XSLT transformation is only one option. You could also fully implement a conversion in ABAP code, e.g. with:
Use CALL TRANSFORMATION id SOURCE XML <xml as string> RESULT <root node> = <itab>.
Refer to the ABAP keyword documentation
Use class/method /ui2/cl_json=>deserialize
and =>serialize
Use class cl_ixml: see Parsing an XML document DOM-based and Parsing an XML document event-based
Upvotes: 2
Reputation: 1951
From what I can tell, there's no standard function module or method call that will automatically convert XML to JSON. If you have just one file, there's a few converters online. If you must solve this problem with ABAP, you're going to have to cook up your own solution or hack some example program online.
If you choose to write a program yourself, consider creating a transformation in the STRANS
transaction to convert your XML data into JSON-XML data, and use a JSON writer to write it into JSON.
This answer is mostly a paraphrase of Horst Keller's post on the matter. He has posted an example program, but your mileage may vary.
Upvotes: 2