Skip to main content

Hello,

I implemented a changed detection on oracle table.

Now I would like to be able to create a json for each change per object.

 For instance, for an object where changes were detected on 5 attributs, below will be the json that I would like to obtain:

{
"ATTRIBUT1": {
"OLD_VALUE": "OLD1",
"NEW_VALUE": "NEW1"
},
"ATTRIBUT2": {
"OLD_VALUE": "OLD2",
"NEW_VALUE": "NEW2"
},
"ATTRIBUT3": {
"OLD_VALUE": "OLD3",
"NEW_VALUE": "NEW3"
},
"ATTRIBUT4": {
"OLD_VALUE": "OLD4",
"NEW_VALUE": "NEW4"
},
"ATTRIBUT5": {
"OLD_VALUE": "OLD5",
"NEW_VALUE": "NEW5"
}
}

How can I proceed to obtain this in fme?

I was tinking of the agregator to group all the changes from the same object (based on an objectid) and then build the json but I don't know how to proceed.

Please keep in mind that the number  and names of attributes will change from one object to another one.

Thanks,

If I understand correctly, you have a separate feature for each change.

 

You can use the JSONTemplater, with a subtemplate to build your desired JSON.

see http://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/jsontemplater.htm, particularly the section "Selecting the Sub-Features to Process"

I would use a sampler to get the first feature for each objectID to the Root, and sent it as well as all the other features to the subtemplate.


If I understand correctly, you have a separate feature for each change.

 

You can use the JSONTemplater, with a subtemplate to build your desired JSON.

see http://docs.safe.com/fme/2017.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/jsontemplater.htm, particularly the section "Selecting the Sub-Features to Process"

I would use a sampler to get the first feature for each objectID to the Root, and sent it as well as all the other features to the subtemplate.

@jdh,

 

Using the JSonTemplater and grouping on the objectifid as you said, I'm having having 5 json file but what I want it is only one json file.

 

 

Yes a change can only be made on one feature at a time. However, a change can affect several attribut of the same feature. In the example described above, we are having 5 attributes that were changes on the same feature

 


Hi @arthy, probably the JSONTemplater would be a solution, but template expression depends on how the feature contains the relevant attributes. What attributes contain the values which should be written into the destination JSON document?


@jdh,

 

Using the JSonTemplater and grouping on the objectifid as you said, I'm having having 5 json file but what I want it is only one json file.

 

 

Yes a change can only be made on one feature at a time. However, a change can affect several attribut of the same feature. In the example described above, we are having 5 attributes that were changes on the same feature

 

Try a subtemplate of

 

{fme:get-attribute("Attribute"): {"OLD_VALUE": fme:get-attribute("OldValue"), "NEW_VALUE":fme:get-attribute("NewValue")}}

 

 

and in the root template

 

{fme:process-features("SUB", "ObjectID", fme:get-attribute("ObjectID"))}

 

 

or if you want the object id reference in the json object, something like

 

{"ObjectID" : fme:get-attribute("ObjectID"), "Changes" : {fme:process-features("SUB", "ObjectID", fme:get-attribute("ObjectID"))}}

 

 

 


Try a subtemplate of

 

{fme:get-attribute("Attribute"): {"OLD_VALUE": fme:get-attribute("OldValue"), "NEW_VALUE":fme:get-attribute("NewValue")}}

 

 

and in the root template

 

{fme:process-features("SUB", "ObjectID", fme:get-attribute("ObjectID"))}

 

 

or if you want the object id reference in the json object, something like

 

{"ObjectID" : fme:get-attribute("ObjectID"), "Changes" : {fme:process-features("SUB", "ObjectID", fme:get-attribute("ObjectID"))}}

 

 

 

@jdh,

 

I tried it and it works perfectly.

 

Thanks

 

 

 


Reply