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: 

Reading Complex JSON String with SimpleTransformation

uwe_isenmann2
Participant
0 Kudos

Hello Together,

Is it possible to read a complex json Response with simple Transformation?

I've found some example coding to create and read JSON with XMLReader and XMLWriter in combination with simpel Transformation.

With a small structure it works very fine. But if I working with a big json Response with nested child structures that are not obligatory. I have big Problems to create a working ST.

Best Regards

Uwe

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

I think that it's the same issue as with XML. You have to specify those elements which are optional (tt:d-cond, etc.)

(and make sure you have applied SAP corrections in case of bugs).

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

I think that it's the same issue as with XML. You have to specify those elements which are optional (tt:d-cond, etc.)

(and make sure you have applied SAP corrections in case of bugs).

0 Kudos

I've allready made some test with conditions but I'm not able to create a running ST.

The Problem is that I have optional Array data: artAttributes (see attached File (it is allready the XML representation of JSON))

I have the following ST:


<tt:d-cond check="exist(artAttributesI">

<object>

     ...

</object>

</tt:d-cond>

But the condition in both cases true.

Maybe I have an error with the condition?

0 Kudos

(that's not the issue but typo in check="exist(artAttributesI" -> check="exist(artAttributes)")

Edit: I looked at your artData.xml, and I think you're right, it's not possible to condition an element based on one of its attributes ("name" here). And you can't either condition its inner element "array" as it's also used for other values of this attribute. So I think you need to exclude the values via ABAP code only, after the transformation.

0 Kudos

Hello Sandra,

Thank you for your Response.

Because artDescription is an attribute I have to use the following code:


<tt:d-cond>

     <object Name="artDescription">

          ...

     </object>

</tt:d-cond>

But now I've understand what is ment with patern in the SAP docu for Simple Transformation conditions.

best regards

0 Kudos

Thanks for the feedback. So, my answer was mostly incorrect (only my remark about "check" was correct, but my remark about "it's not possible to condition an element based on one of its attributes" was wrong, as I thought <object Name="artDescription"> couldn't work).

Please, mark your own answer as correct, to not mislead forum readers.

Former Member
0 Kudos

We started off by using CL_XI_ALERT_JSON_DOCUMENT.
We ended up copying that Class and changing it as it didn't escape characters that well.