Skip to Content

Manipulating incoming JSON with Simple Transformations

Feb 08, 2017 at 07:22 AM


avatar image
Former Member

Hey eyeryone,

I've got the task to save an incoming JSON-File to an ABAP structure. So far so good, I managed to get most of my fields mapped with Simple Transformations.

One problem remains: Within my JSON I get a list of objects like

      }, ... 

I want to save them as a internal table in my structure without creating ddic-structure for every little sub-structure. So my result in the ABAP structure should look like

[identifier] <--optional | customVariableName | customVariableValue  
1                        | xxx1               | yyy1
2                        | xxx2               | yyy2

Is there any way to access the values of the sub-objects in JSON and match them to my preferred way of saving?

I tried many things and read much about different tags in ST, but without success... Maybe some of you know something.

Thanks in advance and kind regards

PS: I should add a note that I will always deserialize files with this ST, but never serialize ABAP data back to JSON. So "One-Way-Solutions" are possible as well.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Horst Keller
Feb 08, 2017 at 07:32 AM

Would it be an option to parse your JSON with methods of the sXML library? See simple example. Maybe you can enhance it for your needs.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks for your answer, Mr. Keller.

I looked at the example and I think I could use it with some adjustments. The problem is that the JSON I get is pretty big, and completely rebuilding it just for the little part of my customVariables is taking way too long.

ST are rather fast with a lot of data, so I chose them. Is there a possibility for ST to fetch the attributes of sub-objects? I tried something like this

<tt:loop ref="$visit.customVariables" name="custvar">
      <tt:cond frq="?">
        <object name="1">
          <str name="customVariableName1">
            <tt:value ref="$custvar.CUSTOMVARIABLENAME"/>
          <str name="customVariableValue1">
            <tt:value ref="$custvar.CUSTOMVARIABLEVALUE"/>

but it didn't work as I hoped it would.

What I will try is using a sub transformation with customVariables as the root node and some magic with parameters, maybe this does help.