Application Development and Automation 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: 
Read only

Json camel case formatted ouput

0 Likes
5,558

Hello,

We are working on a project that sends json formatted payload to a target system via a rest webservice. We would like to follow camel case standard for labels in the json payload. I did a sample program to generate a Json payload and it works fine. But i see that labels are framed from components of the structure. I need to know if its possible to replace the labels with a camel casing format...like messageType in place of MESSAGETYPE  or UniqueID in place of UNIQUEID etc..

Regards

Pradeep

1 ACCEPTED SOLUTION
Read only

dellagustin
Product and Topic Expert
Product and Topic Expert
0 Likes
3,806

Hi,

Try using a simple transformation, than I think you can specify your JSON labels manually and in camel case. Take a look here: https://scn.sap.com/community/abap/blog/2013/04/15/abap-2-json-and-json-2-abap-with-st

Best Regards,

Guilherme.

Hello,

We are working on a project that sends json formatted payload to a target system via a rest webservice. We would like to follow camel case standard for labels in the json payload. I did a sample program to generate a Json payload and it works fine. But i see that labels are framed from components of the structure. I need to know if its possible to replace the labels with a camel casing format...like messageType in place of MESSAGETYPE  or UniqueID in place of UNIQUEID etc..

Regards

Pradeep

11 REPLIES 11
Read only

former_member205488
Active Participant
0 Likes
3,806

Hello!

Could you specity how do you generate JSON?

The field labels you get are in uppercase, are they?

Read only

0 Likes
3,806

Hello,

I have created a flat structure that has nested fields and table in SAP and filled this structure with data. Json payload is created using native SAP native json transformations. Yes, labels are in upper case. See below.

{

"DATA":

{

  "HEADER":

  {

   "UNIQUEID":"XXXXXX",

  .............................

..................

What i need is below:

{

"DATA":

{

  "header":

  {

   "uniqueId":"XXXXXX",

.....................................

Thanks

Pradeep

Read only

0 Likes
3,806

Ok, I get it.

Try to use class CL_TREX_JSON_SERIALIZER. It doesn't translate the labels to upper case. But It has a few lacks which is easy to fix. There is a reference how to do it:

Also, this link could be useful:

Read only

0 Likes
3,806

Thanks for the link...but then i think it keeps everything in lower case. Somewhere i need to indicate the label i want to use. I understand that i have to create a simple transformation for this as per below help link ABAP Keyword Documentation      

and demo program DEMO_ST_JSON_TABLE. Need to see how i can implement this..

Pradeep

Read only

0 Likes
3,806

Label should look like 'UniqueID' 'dateCreated' etc...

Read only

0 Likes
3,806

It's very interesting challenge...

I suppose it is impossible to do it using a transformation of a dictionary structure or local structure, because you cannot declare structure field names using "camelCase". If you do it in ABAP editor the system will translate the field names to upper case anyway.

I think the only way is to create json manually.

Read only

dellagustin
Product and Topic Expert
Product and Topic Expert
0 Likes
3,807

Hi,

Try using a simple transformation, than I think you can specify your JSON labels manually and in camel case. Take a look here: https://scn.sap.com/community/abap/blog/2013/04/15/abap-2-json-and-json-2-abap-with-st

Best Regards,

Guilherme.

Read only

0 Likes
3,806

Hi,

This is working. I need a suggestion. I have a structure with fields including structures and tables. How do i prepare a ST for such a structure. I know that for tables i can use <tt:loop ref=".MYDATA">...and MYDATA is a table coming from CALL TRANSFORMATION and declared as a root name in ST.This works when i send a table. But i need to send a structure and how can i loop thru after passing structure, how can i add name of structure before showing data of structure. How can i do this. I searched for standard examples, but cant find for a nested structure.

Regards

Pradeep

Read only

dellagustin
Product and Topic Expert
Product and Topic Expert
0 Likes
3,806

I started some tests, thinking it would be a piece of cake... all I have now is exceptions and exceptions.

I'll keep you updated if I have positive results.

Read only

dellagustin
Product and Topic Expert
Product and Topic Expert
0 Likes
3,806

Finally! This took me some time to put together, but it was much easier after I looked at this post:

You should aim your transformation to generate this JSON-XML format.

Check my example:

Report: ZGD_TEST (attached)

Transformation (zgd_deep😞


<?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

   <tt:root name="ROOT"/>

   <tt:template>

     <object>

       <str name="ValueA"><tt:value ref="ROOT.VALUE_A"/></str>

       <object name="DeepStructure" tt:ref="ROOT.DEEP_STRUCTURE">

         <str name="ValueB"><tt:value ref="VALUE_B"/></str>

         <array name="SomeTable">

           <tt:loop ref="SOME_TABLE">

             <object>

               <str name="ValueC"><tt:value ref="VALUE_C"/></str>

               <str name="ValueD"><tt:value ref="VALUE_D"/></str>

             </object>

           </tt:loop>

         </array>

       </object>

     </object>

   </tt:template>

</tt:transform>

Best Regards,

Guilherme.

Read only

0 Likes
3,806

For the moment, i have achieved desired result by using XML writer class IF_SXML_WRITER. Need to try with a simple transformation..