07-28-2016 8:46 AM
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.
07-28-2016 10:47 AM
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).
07-28-2016 12:03 PM
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.
07-28-2016 12:44 PM
"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)
07-28-2016 12:55 PM
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
07-28-2016 1:07 PM
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.
07-28-2016 1:21 PM
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
07-28-2016 1:54 PM
You should do more homework and tests. You may read these two documents: Blog post ABAP and JSON, and SAP Library ABAP and JSON.