cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP CPI JSON to XML conversion: Use JsonReader.setLenient(true) to accept malformed JSON

iglmarkus
Explorer
0 Likes
6,986

Hello Experts,

I am getting the this error using standard JSON to XML converter: Use JsonReader.setLenient(true) to accept malformed JSON.

I got the payload from HTTP get consuming 3rd party API. With a groovy script I removed already the first "[" and last "]" (as JSON to XML will fail).

Below the payload and the corresponding error message.

this part of the payload:

"Id":"579dc1e6-e983-4543-917c-f524115db14e","CountryCode":"US","Name":"United States"},{"Id":"7b218eb7-219e-46aa-a4fc-694afedb2fe0","CountryCode":"CA","Name":"Canada"},{"Id":"38a20ece-6356-4a56-919f-959a7c94e9b7",

thanks, Markus

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Markus

The JSON to XML Converter step wants a top-level JSON object, not an array (even though a top-level array is valid JSON). So you need to fit your array into an object. This is one way to do it:

{
  "objects": [
    {
      "Id": "579dc1e6-e983-4543-917c-f524115db14e",
      "CountryCode": "US",
      "Name": "United States"
    },
    {
      "Id": "7b218eb7-219e-46aa-a4fc-694afedb2fe0",
      "CountryCode": "CA",
      "Name": "Canada"
    },
    {
      "Id": "38a20ece-6356-4a56-919f-959a7c94e9b7"
    }
  ]
}

You can accomplish this by adding a Content Modifier step after your API call with the following body expression:

{
  "objects": ${body}
}

This assumes that your API call returns a JSON array.

Regards,

Morten

iglmarkus
Explorer
0 Likes

HI Morten,

it works well!

thanks for your help!!

cheers Markus

MortenWittrock
SAP Mentor
SAP Mentor
0 Likes

Hi Markus

Great, glad to hear it. Since my answer solved your problem, I'd appreciate it if you would accept it as well.

Regards,

Morten

Answers (1)

Answers (1)

naga33
Newcomer
0 Likes
[
    {
        color: "red",
        value: "#f00"
    },
    {
        color: "green",
        value: "#0f0"
    },
    {
        color: "blue",
        value: "#00f"
    },
    {
        color: "cyan",
        value: "#0ff"
    },
    {
        color: "magenta",
        value: "#f0f"
    },
    {
        color: "yellow",
        value: "#ff0"
    },
    {
        color: "black",
        value: "#000"
    }
]