cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot transform JSON document to XML: JSON document does not start with '{'.

2,768

Hi experts,

I have an issue in CPI using the JSON to XML converter, I tried to use it and CPI response me the next message: com.sap.it.xmljson.JsonXmlException: Cannot transform JSON document to XML: JSON document does not start with '{'.

I have the following JSON body that I need to convert to XML

I know the problem is [ at the beginning of the body. My question is, how can I remove that symbol to be able to use the JSON to XML converter?

I appreciate your answers

greetings

Accepted Solutions (1)

Accepted Solutions (1)

RobertQ
Explorer

Hello Sara,

this is a limitation from the Json to XML Converter as stated in the documentation.

You can simply add a content modifier as described their and process the message.

Here an example with a simulation. I also had to add a second "root" element as their is alos a limitation that the root Object can only have one member. So I added a second root (the name can be adjusted in the Converter).

Content Modifier:

JSON to XML Converter:

Simulation Body input:

Simulation Body Middle:

Simulation Body End:

I hope this helps you with your issue.

Best Regards

Robert

0 Kudos

Hi Robert,

Your solutions works,

Thanks for your help

RobertQ
Explorer
0 Kudos

Hello jaimestrada,

if the solution works, please mark my answer as accepted, so other peaople can find this solution more easily.

Best Regards

Robert

Answers (2)

Answers (2)

chris_75
Explorer
0 Kudos

Hi Rian,

another simple solution without adding an additional root tag to the payload is to insert a script step which removes the first an the last String

def inputJson = message.getBody(String)
def outputJson = inputJson.substring(1, inputJson.length()-1)
message.setBody(outputJson)
return message
0 Kudos

Hi Christian,

I proved your solution but I recive another error:

com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 519 path $

0 Kudos

Hi Ryan, this is the beginning of the message, this is the json that the server responds. I want to know how I can delete that symbol