Question

Dynamic Attribute creation


Badge

I have a json which i am getting through http caller.

This json contains data as well as schema details.

The schema details are like this

Column Name, ColumnIdentifier

 

and Data is like this [{ColoumnIdentifier : Value}]

 

Now i want to create new attributes based on schema details.

I have looked into python caller but i think you cannot create new attributes.

 

is there any transformer by which i can create new attributes using my json as an input?

or a python function to create new attributes


10 replies

Userlevel 5
Badge +25
The JSONFlattener and/or JSONFragmenter should do the trick, although if you want to work with those attributes in other FME transformers you'll need to expose them (and in order to do that you'll need to know what they're called)
Badge
The JSONFlattener and/or JSONFragmenter should do the trick, although if you want to work with those attributes in other FME transformers you'll need to expose them (and in order to do that you'll need to know what they're called)

Thats the thing. It is dynamic. I cannot hardcode name of columns. This is why i am looking for a way to create new attributes based on that JSON.

I am using JSON Fragmenter and i am showing them in inspector but how can i create new attributes

Userlevel 1
Badge +21

Thats the thing. It is dynamic. I cannot hardcode name of columns. This is why i am looking for a way to create new attributes based on that JSON.

I am using JSON Fragmenter and i am showing them in inspector but how can i create new attributes

What is the end result? If you are writing out to another file, it is not necessary to expose the attributes. If you need to expose the attributes on the canvas, your workspace is no longer dynamic

Badge

What is the end result? If you are writing out to another file, it is not necessary to expose the attributes. If you need to expose the attributes on the canvas, your workspace is no longer dynamic

Very good point indeed.

 

Yes as an end result i am writing a feature class.
Badge

Very good point indeed.

 

Yes as an end result i am writing a feature class.

But still there is not way to create new attributes ?

 

from some list or json
Userlevel 1
Badge +21

If you want to create new attributes from values this can be done in an attributecreator, so you use the value in a one column to create the attribute name and the value in another to set the value, e.g.

The attributes will be created and can be seen in the feature information window and can be written out dynamically but will not be available on the canvas

 

You can use a pythoncaller to do the same

Badge

If you want to create new attributes from values this can be done in an attributecreator, so you use the value in a one column to create the attribute name and the value in another to set the value, e.g.

The attributes will be created and can be seen in the feature information window and can be written out dynamically but will not be available on the canvas

 

You can use a pythoncaller to do the same

Hi

Thank you i am trying this approach and i tried exporting it to csv file for a test.

Still do not works. Is there something which i am missing ?

Userlevel 4
Badge +26

Hi

Thank you i am trying this approach and i tried exporting it to csv file for a test.

Still do not works. Is there something which i am missing ?

You will need to create a schema feature. You can give the SchemaSetter a go. It will add a list list in the structure which FME can use to define the schema on output. The transformer will add a list to each feature but you only need one feature. The feature with the schema list must be the first to get to the writer.

There are two special attributes you can set on the SchemaFeature which will help:

"fme_schema_handling"

And

"fme_feature_type_name"

You should double check the attribute names (I just wrote from memory)

set fme_schema_handling to: schema_only

and the fme_feature_type_name should the output feature type which all the rest of the features need to have set.

Here is a bit of a tutorial with some actual examples:

https://knowledge.safe.com/articles/1051/dynamic-workflow-tutorial-destination-schema-is-de-2.html

Badge

If you want to create new attributes from values this can be done in an attributecreator, so you use the value in a one column to create the attribute name and the value in another to set the value, e.g.

The attributes will be created and can be seen in the feature information window and can be written out dynamically but will not be available on the canvas

 

You can use a pythoncaller to do the same

@ebygomm​ It works perfectly fine the way you describe it. But what is the point to create a non exposed attribute. One would work with its content, won't I?

Userlevel 1
Badge +21

@ebygomm​ It works perfectly fine the way you describe it. But what is the point to create a non exposed attribute. One would work with its content, won't I?

You can write out unexposed attributes dynamically, so there are use cases where you would want to create an attribute and write that to a file, without any requirement to work with the content of those unexposed attributes.

Reply