Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

problem in passing JSON as a input with out Array

Former Member
0 Kudos

Dear Experts ,

            i am developing a report that should convert JSON format to ABAP internal table, when i am passing JSON input with array output is coming properly . But i want send JSON format with out Array . Is it possible ?

Suppose Json format is      '{"uuid": "27e832fe48c39", "platform": "Android", "version": "6.0" }' If i use this input i am getting error .

Succeed with      '{"XXXXX" : [{"uuid": "27e832fe48c39", "platform": "Android", "version": "6.0" } ] }' .


Regards

Venkatesh.

7 REPLIES 7

Sandra_Rossi
Active Contributor
0 Kudos

I don't understand where the table is in your first JSON. I just see a structure made of 3 fields. Don't you mean: [{"uuid": "27e832fe48c39", "platform": "Android", "version": "6.0" }] (a table of one line made of 3 fields).

Anyway, I think the ABAP transformation concept requires that there is a named JSON root element to assign it to the data object (call transformation ... result ROOTNAME = dataobject), because it's based on the previous XML transformation technology, so I'm afraid you need to add one in your JSON to make it work.

Maybe you can make it work directly using or other JSON projects (slower performance).

0 Kudos

Providing my program , i dont wanna provide that array ( "xxxx") in the JSON input. is it possible ? how ?


DATA DAT TYPE STRING VALUE

'{"XXXX" : [{"uuid": "27e832fee9e48c39", "platform": "Android", "version": "6.0", "manufacturer": "motorola","serial":"TA99301XFK"},' &
           '{"uuid": "27e832fee9e48c39", "platform": "Android", "version": "6.0", "manufacturer": "motorola","serial":"TA99301XFK"}]}'.

  TYPES  : BEGIN OF TY,
           UUID         TYPE STRING,
           PLATFORM     TYPE STRING,
           VERSION      TYPE STRING,
           MANUFACTURER TYPE STRING,
           SERIAL       TYPE STRING,
           END OF TY.


DATA : WA TYPE TY ,
        IT TYPE TABLE OF TY .

FIELD-SYMBOLS: <FS1> TYPE ANY.


DATA: OUT TYPE REF TO DATA.


DATA : PARSEE TYPE REF TO CL_GIS_JSON_PARSER.

CREATE OBJECT PARSEE.

CALL METHOD PARSEE->IF_GIS_PARSER~DESERIALIZE

   EXPORTING

     NATIVE_STRING = DAT

   CHANGING

     ABAP_DATA     = OUT .

ASSIGN OUT->* TO <FS1>.
* IT[] = OUT .
ASSIGN COMPONENT 1 OF STRUCTURE <FS1> TO FIELD-SYMBOL(<FS2>) .


IT[] = <FS2>.

WRITE :/ DAT .

SKIP 3 .

LOOP AT IT INTO WA.

WRITE:/ WA-UUID, WA-PLATFORM,WA-VERSION,WA-MANUFACTURER,WA-SERIAL.
NEW-LINE .

ENDLOOP.

0 Kudos

"You don't want", but what can you do when there's no other way?

By the way, you should better use the official way to work with JSON, i.e. SXML (refer to the ABAP documentation of CALL TRANSFORMATION - JSON)

0 Kudos

i need output like this

not like this

I Dont want that separate pop-up .

please suggest me to get the output as above .

Regards

0 Kudos

The second screen capture is just what you see on the screen, but there are no space and new line characters in the string data object.

The only issue you may have with CALL TRANSFORMATION JSON is the lower case of element names in the object (uuid, Platform), because ABAP uses upper case (UUID, PLATFORM). If you have only 4 fields, I would simply replace "UUID": with "uuid": etc.

0 Kudos

Thank you for your valuable suggestion sir

      suppose i have a database table that contain Json data in one field,  how can i convert it into one internal table sir !!

And

you said "The second screen capture is just what you see on the screen, but there are no space and new line characters in the string data object." so , you mean can i remove that pop-up window !!

sorry actually i am very new to this topics

regards

0 Kudos

You should do more homework and tests. You may read these two documents: Blog post ABAP and JSON, and SAP Library ABAP and JSON.