cancel
Showing results for 
Search instead for 
Did you mean: 

How do I display the SAP ODATA response with a nested JSON Structure??

Former Member
0 Kudos

Hi,

I have a requirement to display the JSON Response using a nested structure rather than a flat structure.

Kindly provide a solution for the same.

Thanks & Regards,

Thejus Singh J

Ph no. (91)9686557664

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos
  1. {
  2.     "MAIN": [
  3.         {
  4.             "HTEXT1": [
  5.                 {
  6.                     "Text10": [
  7.                         {
  8.                             "img": "images/i100.png",
  9.                             "text": "text100",
  10.                             "price": "5",
  11.                             "popular": "1",
  12.                             "url": "..."
  13.                         },
  14.                         {
  15.                             "img": "images/i101.png",
  16.                             "text": "text101",
  17.                             "price": "10",
  18.                             "popular": "1",
  19.                             "url": "..."
  20.                         },
  21.                         {
  22.                             "img": "images/i102.png",
  23.                             "text": "text102",
  24.                             "price": "15",
  25.                             "popular": "1",
  26.                             "url": "..."
  27.                         }
  28.                     ]
  29.                 },
  30. .....

I need a response as shown above.

Thanks & Regards,

Thejus Singh J

Ashg1402
Contributor
0 Kudos

hi,

Check this link, may e this will help.

Former Member
0 Kudos

Thanks for your time Ashish.

But how can I achieve this in my SAP Odata response through SAP Netweaver Gateway.

Thanks & Regards,

Thejus Singh J

AshwinDutt
Active Contributor
0 Kudos

Hello Thejus,

Below will give an idea. (Create your own entities with meaningful names)

Create 3 entities :

Header, Item1 & Item2

Create association between Header & Item1 with cardinality 1 to N

Create association between Item1 & Item2 with cardinality 1 to N

Create Navigation Item1 between Header & Item1

Create Navigation Item2 between Item1 & Item2

Implement Expand Entity Set method.

Inside this define a deep structure and a table type which represents the above data model.

Fill the data accordingly in it and return the final table as GW response.

At the end append the navigation property ITEM1/ITEM2 to et_expanded_tech_clauses

Your URL would like this :

/sap/opu/odata/sap/<ServiceName>/HeaderSet?$expand=Item1/Item2

This way you will get the nested response which you want. This holds all your headers and their corresponding items data.

Check this for the technical help.

Regards,

Ashwin