cancel
Showing results for 
Search instead for 
Did you mean: 

REST Receiver - JSON Format - Unnamed array inside array - Remove FieldNames in structure

0 Kudos

Hi all,

Is there any way i can build an XML structure on SAP PI 7.5 and then convert it to JSON (using REST adapter) to generate this:

{  
   "Headers":[  
      "ID",
      "City",
      "Country"
   ],
   "Lines":[  
      [  
         12345,
         "NEWYORK",
         "USA"
      ],
      [  
         12346,
          "TORONTO",
         "CANADA"
      ],
      [  
         12347,
         "WASHINGTON",
         "USA"
      ]
   ]
}

this is the template of previous structure:

{  
   "Headers":[  
      "FieldName1",
      "FieldName2",
      "FieldName3"
   ],
   "Lines":[  
      [  
         FieldName1-Value1,
         FieldName2-"Value1",
         FieldName3-"Value1",
      ],
      [  
         FieldName1-Value2,
         FieldName2-"Value2",
         FieldName3-"Value2",
      ],
      [  
         FieldName1-Value3,
         FieldName2-"Value3",
         FieldName3-"Value3",
      ]
   ]
}

The problem is with the "Lines" structure. There is an array inside the array "Lines" but it has no name on it.

I was thinking to use JAVA mapping to generate it, but i prefer to use a standard way.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor

Too remove list tag add a parameter for adapter module as : setIgnoredElements with value List

0 Kudos

Thanks, i will try with this solution and let you know... i have to apply SP007 to our PI system to test it.

Answers (3)

Answers (3)

former_member190293
Active Contributor

Hi Israel!

Looking at your template the first question is: how should respective XML structure for your JSON input look like, since you describe unnamed array inside your JSON?

Regards, Evgeniy.

0 Kudos

Hi Evgeniy,

That is the issue we have... the unnamed array.

This is the way we think to build the XML target structure.

When we send this to REST adapter, the Headers looks good but not the Lines.

{  
   "Headers":[  
      "ID",
      "City",
      "Country"
   ],
   "Lines":[  
      "12345,\"NEWYORK\",\"USA\"",
      "12346,\"TORONTO\",\"CANADA\"",
      "12347,\"WASHINGTON\",\"USA\""
   ]
}

Do you know how can we have the unnamed array inside lines?

Just as reference, this is the source Structure...


0 Kudos

I did it using java mapping to convert XML into JSON (on mapping) and remove the check to convert from XML to JSON in communication channel receiver.

The solution proposed by Manoj K works, but our PI environment is not updated to SP007.

0 Kudos

I already build a structure:

I paste the below XML to this Page: https://www.freeformatter.com/xml-to-json-converter.html#ad-output

<ns0:MT_API xmlns:ns0="http://test.com/API"><Headers><List>ID</List><List>City</List><List>Country</List></Headers><Lines><List><List>12345</List><List>NEWYORK</List><List>USA</List></List><List><List>12346</List><List>TORONTO</List><List>CANADA</List></List><List><List>12347</List><List>WASHINGTON</List><List>USA</List></List></Lines></ns0:MT_API>

and it converts the XML to the JSON i expected:

{
  "Headers": [
    "ID",
    "City",
    "Country"
  ],
  "Lines": [
    [
      "12345",
      "NEWYORK",
      "USA"
    ],
    [
      "12346",
      "TORONTO",
      "CANADA"
    ],
    [
      "12347",
      "WASHINGTON",
      "USA"
    ]
  ]
}

but when i run it on SAP PI, it returns:

{  
   "Headers":[  
      {  
         "List":[  
            "ExternalID",
            "City",
            "Country"
         ]
      }
   ],
   "Lines":[  
      {  
         "List":[  
            {  
               "List":[  
                  12345,
                  "MONTERREY",
                  "MEXICO"
               ]
            },
            {  
               "List":[  
                  12346,
                  "GUADALAJARA",
                  "MEXICO"
               ]
            },
            {  
               "List":[  
                  12347,
                  "CDMX",
                  "MEXICO"
               ]
            }
         ]
      }
   ]
}

how can I remove the "List" tag?